Skip to content

Commit 21cd0ff

Browse files
committed
1. Linked List Cycle
1 parent e156dd5 commit 21cd0ff

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

linked-list-cycle/sunjae95.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @description
3+
* brainstorming:
4+
* hash table
5+
*
6+
* n = length of head
7+
* time complexity: O(n)
8+
* space complexity: O(n)
9+
*/
10+
var hasCycle = function (head) {
11+
const set = new Set();
12+
let node = head;
13+
14+
while (node) {
15+
if (set.has(node)) return true;
16+
set.add(node);
17+
node = node.next;
18+
}
19+
20+
return false;
21+
};

0 commit comments

Comments
 (0)