Find the middle node

odd: the middle / even: Mid是前半段的最后一个

public ListNode findMiddle(ListNode head) {
        //note: how to assign the first step
        ListNode mid = head, end = head.next;
        while(end != null && end.next != null) {
            end = end.next.next;
            mid = mid.next;
        }
        return mid;
}

results matching ""

    No results matching ""