My Blog List

[LeetCode Solution] List Cycle

Analysis

  • use two pointers to traversal the list
  • the slow one jump one node per step, the fast one jump two nodes per step
  • two pointer will meet if and only if there is a cycle

Code