链表找中点(根据需求找偏左或偏右)

偶数找偏左,奇数找中点

        ListNode slow = head;
        ListNode fast = head.next;
        while(fast != null && fast.next != null){
            slow = slow.next;
            fast = fast.next.next;
        }    

偶数找偏右,奇数找中点

        ListNode slow = head;
        ListNode fast = head;
        while(fast != null && fast.next != null){
            slow = slow.next;
            fast = fast.next.next;
        }
上一篇:leetcode 9.回文数


下一篇:MySQL数据库优化总结