Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb08f141

Browse files
876_Middle_of_the_Linked_List
1 parent11414c7 commitb08f141

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎876_Middle_of_the_Linked_List.java‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode(int x) { val = x; }
7+
* }
8+
*/
9+
classSolution {
10+
// public ListNode middleNode(ListNode head) {
11+
// List<ListNode> array = new ArrayList<ListNode>();
12+
// while (head != null) {
13+
// array.add(head);
14+
// head = head.next;
15+
// }
16+
// return array.get(array.size() / 2);
17+
// }
18+
publicListNodemiddleNode(ListNodehead) {
19+
ListNodefast,slow;
20+
fast =slow =head;
21+
while (fast !=null &&fast.next !=null) {
22+
slow =slow.next;
23+
fast =fast.next.next;
24+
}
25+
returnslow;
26+
}
27+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp