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

โ€Žlinked-list-cycle/gmlwls96.kt

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)