1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
var hasCycle = function(head) {
let [slow, fast, flag] = [head, head, false];
while (fast && fast.next) { fast = fast.next.next; slow = slow.next;
if (fast == slow) { flag = true; break; } }
return flag; };
|