Skip to content

Commit cd9e4f4

Browse files
committed
feat: 문제풀이 추가
1 parent a4473c8 commit cd9e4f4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

linked-list-cycle/hwanmini.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// 시간복잡도: O(n)
2+
// 공간복잡도: O(1)
3+
4+
/**
5+
* Definition for singly-linked list.
6+
* function ListNode(val) {
7+
* this.val = val;
8+
* this.next = null;
9+
* }
10+
*/
11+
12+
/**
13+
* @param {ListNode} head
14+
* @return {boolean}
15+
*/
16+
var hasCycle = function(head) {
17+
let fastPointer = head;
18+
let slowPointer = head;
19+
20+
while (fastPointer && fastPointer.next) {
21+
slowPointer = slowPointer.next;
22+
fastPointer = fastPointer.next.next
23+
24+
if (fastPointer === slowPointer) return true
25+
26+
}
27+
28+
return false
29+
};

0 commit comments

Comments
 (0)