javascript
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {boolean}
*/
var hasCycle = function (head) {
if (head === null || head.next === null) return false
let slow = head
let fast = head.next.next
while (fast) {
if (slow === fast) {
return true
}
if (fast.next) {
fast = fast.next.next
} else {
return false
}
slow = slow.next
}
return false
}