https://leetcode.cn/problems/middle-of-the-linked-list/
使用快慢指针
1 lass Solution { 2 public ListNode middleNode(ListNode head) { 3 // 排除为空情况 4 if(head == null){ 5 return null; 6 } 7 // 使用快慢指针 8 ListNode slow = head; 9 ListNode fast = head; 10 11 while(fast != null && fast.next != null){ 12 slow = slow.next; 13 fast = fast.next.next; 14 } 15 return slow; 16 } 17 }
标签:head,slow,ListNode,876,fast,next,链表,null,节点 From: https://www.cnblogs.com/luyj00436/p/17106784.html