总结

1,链表找中间节点

        ListNode fast = head;
        ListNode slow = head;
        while (fast != null && fast.next != null)
        {
            slow = slow.next;
            fast = fast.next.next;
        }
        if (fast != null)  是奇数  ,前一半比后一般多一
        { 
            slow = slow.next;
        }
View Code

2.链表反转

    public ListNode reverse(ListNode head)
    {
        ListNode pre = null;
        while (head != null)
        {
            ListNode next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }
View Code

 

posted on 2017-03-29 14:36  wheleetcode  阅读(49)  评论(0)    收藏  举报