Site icon TuringPlanet

876.Middle of the Linked List 链表的中间结点【LeetCode单题讲解系列】

无法播放?请 点击这里 跳转到Youtube
切换视频源:

题目: https://leetcode.com/problems/middle-of-the-linked-list/

class Solution {
    public ListNode middleNode(ListNode head) {
        ListNode slow = head, fast = head;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }
        return slow;
    }
}
Exit mobile version