categories: [Blog,Algorithm]
876. 链表的中间结点
有多个返回第二个
public ListNode middleNode(ListNode head) {ListNode[] A = new ListNode[100];int t = 0;while (head != null) {A[t++] = head;head = head.next;}return A[t / 2];}作者:LeetCode-Solution链接:https://leetcode-cn.com/problems/middle-of-the-linked-list/solution/lian-biao-de-zhong-jian-jie-dian-by-leetcode-solut/
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;}
