Python solution
make sure the last element you get is the index that you start.\nlike S[0] = {A[0], A[5], A[6], A[2]} = {5, 6, 2, 0}, you can find S[0] = {5, 6, 2, 0}\nbad code
make sure the last element you get is the index that you start.\nlike ```S[0] = {A[0], A[5], A[6], A[2]} = {5, 6, 2, 0}```, you can find S[**0**] = {5, 6, 2, **0**}\nbad code but it works, i get it :(\n```\nclass Solution(object):\n    def arrayNesting(self, nums):    \n        count , sum_ , n = 1, [] , len(nums)\n        for i in range(n):\n            temp = i\n            if nums[i] != n:\n                while 1:\n                    if nums[temp] == i:\n                        sum_.append(count)\n                        nums[temp] = n\n                        count = 1\n                        break\n                    else:\n                        temp1 = nums[temp]\n                        nums[temp] = n\n                        temp = temp1\n                        count += 1\n        return max(sum_)\n```
['Python']