Skip to content

Commit 089b114

Browse files
committed
[week2] solve 141. Linked List Cycle
1 parent 24af36f commit 089b114

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

linked-list-cycle/bky373.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* - 문제: https://leetcode.com/problems/linked-list-cycle/
3+
* - TC: O(N)
4+
* - SC: O(1)
5+
*/
6+
public class Solution {
7+
public boolean hasCycle(ListNode head) {
8+
if (head == null || head.next == null) {
9+
return false;
10+
}
11+
int min = -10001;
12+
13+
while (head.next != null) {
14+
if (head.next.val == min) {
15+
return true;
16+
}
17+
head.val = min;
18+
head = head.next;
19+
}
20+
return false;
21+
}
22+
}

0 commit comments

Comments
 (0)