Open pwstrick opened 4 years ago
141. 环形链表
/** * 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) return false; let fast = head.next, slow = head; while(fast != slow) { if(fast == null || fast.next == null) return false; slow = slow.next; fast = fast.next.next; } return true; };
141. 环形链表