The basic idea is to find the longest circle
, in those index-pointer-chains
. Start from unvisited each number, and then marked this position as visited, find the value whose index is the previous value. If the next value is visited, stop and then update the maxLen.
https://discuss.leetcode.com/topic/90538/c-java-clean-code-o-n