Skip to content

Commit a39d1bc

Browse files
committed
Time: 50 ms (98.26%), Space: 53 MB (58.37%) - LeetHub
1 parent f91e87a commit a39d1bc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
15+
let slow = head;
16+
let fast = head;
17+
while (slow != null && fast!=null && fast.next != null) {
18+
slow = slow.next;
19+
fast = fast.next.next;
20+
if (slow == fast) return true;
21+
}
22+
return false;
23+
};

0 commit comments

Comments
 (0)