LintCode 35---翻转链表

public class Solution {
    /**
     * @param head: n
     * @return: The new head of reversed linked list.
     */
    public ListNode reverse(ListNode head) {
     if(head == null || head.next == null) return head;
        ListNode prev = null;
        ListNode current = head;
        ListNode forward = current.next;
        while(forward != null){
            current.next = prev;
            prev = current;
            current = forward;
            forward = forward.next;
        }
        current.next = prev;
        return current;
    }
}

 

上一篇:从Android ZXing IntentIntegrator提取结果


下一篇:LintCode 14---二分查找