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

Commit106a6ea

Browse files
refactor 142
1 parent0d06265 commit106a6ea

File tree

1 file changed

+17
-27
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+17
-27
lines changed

‎src/main/java/com/fishercoder/solutions/_142.java

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,25 @@
22

33
importcom.fishercoder.common.classes.ListNode;
44

5-
/**
6-
* 142. Linked List Cycle II
7-
8-
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
9-
10-
Note: Do not modify the linked list.
11-
12-
Follow up:
13-
Can you solve it without using extra space?
14-
*/
155
publicclass_142 {
166

17-
publicstaticclassSolution1 {
18-
publicListNodedetectCycle(ListNodehead) {
19-
ListNodeslow =head;
20-
ListNodefast =head;
21-
while (fast !=null &&fast.next !=null) {
22-
slow =slow.next;
23-
fast =fast.next.next;
24-
if (slow ==fast) {
25-
ListNodeslow2 =head;
26-
while (slow2 !=slow) {
27-
slow =slow.next;
28-
slow2 =slow2.next;
29-
}
30-
returnslow;
7+
publicstaticclassSolution1 {
8+
publicListNodedetectCycle(ListNodehead) {
9+
ListNodeslow =head;
10+
ListNodefast =head;
11+
while (fast !=null &&fast.next !=null) {
12+
slow =slow.next;
13+
fast =fast.next.next;
14+
if (slow ==fast) {
15+
ListNodeslow2 =head;
16+
while (slow2 !=slow) {
17+
slow =slow.next;
18+
slow2 =slow2.next;
19+
}
20+
returnslow;
21+
}
22+
}
23+
returnnull;
3124
}
32-
}
33-
returnnull;
3425
}
35-
}
3626
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp