Skip to content

Commit 10ca053

Browse files
authored
Create 141. Linked List Cycle
1 parent af03a96 commit 10ca053

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val) {
4+
* this.val = val;
5+
* this.next = null;
6+
* }
7+
*/
8+
9+
/**
10+
* @param {ListNode} head
11+
* @return {boolean}
12+
*/
13+
var hasCycle = function(head) {
14+
let curr = head;
15+
let visited = new Set();
16+
17+
while (curr !== null){
18+
if (visited.has(curr)){
19+
return true;
20+
}
21+
visited.add(curr);
22+
curr = curr.next;
23+
}
24+
25+
return false;
26+
};

0 commit comments

Comments
 (0)