206. Reverse Linked List 链表倒置

这是一道很常见的链表算法题,题意一般是实现某个单向链表的反向重置。我在百度面试过程中被问到。我在阅读材料时,这个道题曾是微软面试题。

需要一个标记指针,和两个辅助指针。每次前进标记指针,把其他两个指针位点进行调整。

public class Solution {
    public ListNode reverseList(ListNode head) {
        ListNode front = null;
        ListNode NEXT = null;
        ListNode index = head;
        while(index != null){
            NEXT = index.next;
            index.next = front;
            front = index;
            index = NEXT;
        }
        return front;
    }
}

 

posted @ 2016-04-10 22:54  ProWhalen  阅读(128)  评论(0编辑  收藏  举报