https://leetcode.cn/problems/linked-list-cycle-ii/
/** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } */ /** * @param {ListNode} head * @return {ListNode} */ var detectCycle = function(head) { let slow = head; let fast = head; while (fast !== null && fast.next !== null) { slow = slow.next; fast = fast.next.next; if (slow == fast) { slow = head; while (slow !== fast) { slow = slow.next; fast = fast.next; } return slow; } } return null; };
原创文章,作者:czhdawn,如若转载,请注明出处:https://www.czhdawn.cn/archives/4942