Skip to content

Commit 7b9e6a1

Browse files
committed
add 141
1 parent 3f23510 commit 7b9e6a1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

easy/141-linked-list-cycle.js

Lines changed: 24 additions & 0 deletions
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+
var hasCycle = function(head) {
14+
let t = head;
15+
while (t !== null) {
16+
t.visited = t.visited || 0;
17+
t.visited++;
18+
if (t.visited > 1 && t.next) {
19+
return true;
20+
}
21+
t = t.next;
22+
}
23+
return false;
24+
};

0 commit comments

Comments
 (0)