C++ DFS Solution
Runtime: 22 ms, faster than 45.01% of C++ online submissions for Array Nesting.\nMemory Usage: 30.8 MB, less than 26.21% of C++ online submissions for Array Nes
Runtime: 22 ms, faster than 45.01% of C++ online submissions for Array Nesting.\nMemory Usage: 30.8 MB, less than 26.21% of C++ online submissions for Array Nesting.\n\n`We have to find the longest cycle length in the array which can do easily using DFS.`\n\n```\nclass Solution {\npublic:\n    \n    int dfs(vector<int>& nums, int index)\n    {\n        if(index==-1)return -1;\n        \n        int val = nums[index];\n        nums[index]=-1;\n        \n        return dfs(nums,val) + 1;        \n    }\n    \n    int arrayNesting(vector<int>& nums) {\n     \n        int maxLen = -1;\n        for(int i=0;i<nums.size();i++)\n        {\n            if(nums[i]<0)continue;\n            \n            maxLen = max(maxLen,dfs(nums,i));\n        }\n        \n        return maxLen;\n    }\n};\n```
['Array', 'Depth-First Search', 'C']