标签:
/* * three argvs: headNext(the head‘s next), tmp(move forward), node(the removed ListNode). */ public ListNode reverseList(ListNode head) { if (head == null || head.next == null) { return head; } ListNode headNext = head.next; ListNode tmp = headNext; while (tmp.next != null) { ListNode node = tmp.next; tmp.next = node.next; head.next = node; node.next = headNext; headNext = head.next; } ListNode newHead = head.next; head.next = null; tmp.next = head; return newHead; }
标签:
原文地址:http://www.cnblogs.com/lasclocker/p/4622643.html