MCPcopy Create free account
hub / github.com/PengFTang/Algorithms-in-Java / detectCycle

Method detectCycle

Two-Pointer/LinkedLisCycle.java:8–30  ·  view source on GitHub ↗

The following code solves the problem of detecting the staring node of a cycle in a linked list if there is one. The key idea is to use a slow and a fast pointer traversing the list, where slow moves one step forward at a time and the fast moves two steps forward at a time. If they is no cycle, fast

(ListNode head)

Source from the content-addressed store, hash-verified

source not stored for this graph (policy: none)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected