鏈表中位數(Middle of the Linked List)

一、學習要點
1.鏈表知識的回顧;
2.鏈表結點數組;
二、代碼
class Solution {
public ListNode middleNode(ListNode head) {
ListNode[] array = new ListNode[100];
int count = 0;
while (head != null) {
array[count++] = head;
head = head.next;
}
return array[count / 2];
}
};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章