Skip to content

Commit 542b037

Browse files
authored
Create 141-linked-list-cycle.js
1 parent 31ae3e3 commit 542b037

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

141-linked-list-cycle.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
const hasCycle = function(head) {
14+
const seen = []
15+
while(head != null) {
16+
if(seen.indexOf(head) !== -1) {
17+
return true
18+
} else {
19+
seen.push(head)
20+
}
21+
head = head.next
22+
}
23+
return false
24+
};

0 commit comments

Comments
 (0)