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

Commitbd9ce92

Browse files
linked list cycle II
1 parenta574273 commitbd9ce92

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
packagemedium;
2+
3+
importclasses.ListNode;
4+
5+
publicclassLinkedListCycleII {
6+
7+
publicListNodedetectCycle(ListNodehead) {
8+
ListNodeslow =head,fast =head;
9+
while (fast !=null &&fast.next !=null) {
10+
slow =slow.next;
11+
fast =fast.next.next;
12+
if (slow ==fast) {
13+
ListNodeslow2 =head;
14+
while (slow2 !=slow) {
15+
slow =slow.next;
16+
slow2 =slow2.next;
17+
}
18+
returnslow;
19+
}
20+
}
21+
returnnull;
22+
}
23+
}

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
|157|[Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4/)|[Solution](../../blob/master/EASY/src/easy/ReadNCharactersGivenRead4.java)| O(n)|O(1)| Easy|
8888
|155|[Min Stack](https://leetcode.com/problems/min-stack/)|[Solution](../../blob/master/EASY/src/easy/MinStack.java)| O(1)|O(n) | Easy| Stack
8989
|151|[Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/)|[Solution](../../blob/master/MEDIUM/src/medium/ReverseWordsinaString.java)| O(n)|O(n)| Medium|
90+
|142|[Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/)|[Solution](../../blob/master/MEDIUM/src/medium/LinkedListCycleII.java)| O(n)|O(1) | Medium| Linked List
9091
|141|[Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/)|[Solution](../../blob/master/EASY/src/easy/LinkedListCycle.java)| O(n)|O(1) | Easy| Linked List
9192
|140|[Word Break II](https://leetcode.com/problems/word-break-ii/)|[Solution](../../blob/master/HARD/src/hard/WordBreakII.java)| ? |O(n^2) | Hard| Backtracking/DFS
9293
|139|[Word Break](https://leetcode.com/problems/word-break/)|[Solution](../../blob/master/MEDIUM/src/medium/WordBreak.java)| O(n^2)|O(n) | Medium| DP

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp