啟動flannel網路功能報錯
阿新 • • 發佈:2021-01-22
技術標籤:LeetCode筆記
給定一個頭結點為 head 的非空單鏈表,返回連結串列的中間結點。
如果有兩個中間結點,則返回第二個中間結點。
示例 1:
輸入:[1,2,3,4,5]
輸出:此列表中的結點 3 (序列化形式:[3,4,5])
返回的結點值為 3 。 (測評系統對該結點序列化表述是 [3,4,5])。
思路:將連結串列儲存到List中,然後返回一半以後節點的資料。
class Solution {
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];
}
}