class Solution(object):
def arrayNesting(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
ans=0
step = 0
seen = [False] * n
for i in range(len(nums)):
while not seen[i]:
seen[i] = True
i, step = nums[i], step + 1
ans = max(ans, step)
step = 0
return ans