Skip to content

Commit aa93499

Browse files
committed
[week9](gmlwls96) Linked List Cycle
1 parent f2b9477 commit aa93499

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
// μ‹œκ°„ : O(n)
3+
// μ„ΈνŠΈμ— head.val 값을 μΆ”κ°€ν•˜λ©΄μ„œ λ™μΌν•œ 값이 μžˆλŠ”μ§€ 체크. λ™μΌν•œ 값이 μ‘΄μž¬ν•˜λ©΄ μˆœνšŒν•œλ‹€κ³  νŒλ‹¨.
4+
fun hasCycle(head: ListNode?): Boolean {
5+
val set = mutableSetOf<Int>()
6+
var next = head
7+
while (next != null) {
8+
if (set.contains(next.`val`)) {
9+
return true
10+
}
11+
set.add(next.`val`)
12+
next = next.next
13+
}
14+
return false
15+
}
16+
}

β€Žlongest-substring-without-repeating-characters/gmlwls96.ktβ€Ž

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
Β (0)