[C++/Python] Find the longest length between cycles - with Picture - Clean & Concise
Version 1: Straightforward - O(N) Space\n- Elements in the same set will form a cycle.\n- We just traverse elements x in nums:\n\t- If x is not visited then we 
**Version 1: Straightforward - O(N) Space**\n- Elements in the same set will form a cycle.\n- We just traverse elements `x` in `nums`:\n\t- If `x` is not visited then we `dfs(x)` to find elements in the same cycle with node `x`.\n\t- Update the `ans` if the current cycle has length greater than `ans`.\n- Check the following picture for more clearly.\n\n![image](https://assets.leetcode.com/users/images/07a4b748-a8de-4a95-abe0-165255bccee1_1630563859.4152162.png)\n\n<iframe src="https://leetcode.com/playground/2ivJo73V/shared" frameBorder="0" width="100%" height="360"></iframe>\n\n**Complexity**\n- Time: `O(N)`, where `N <= 10^5` is number of elements in `nums` array.\n- Space: `O(N)`\n\n---\n\n**Version 2: In space modification - O(1) Space**\n- We can achieve O(1) in space by modify `nums` array directly, mark `nums[i] = -1` with the meaning `visited[i] = True`.\n\n<iframe src="https://leetcode.com/playground/BKa3zB4D/shared" frameBorder="0" width="100%" height="380"></iframe>\n\n**Complexity**\n- Time: `O(N)`, where `N <= 10^5` is number of elements in `nums` array.\n- Space: `O(1)`\n\nIf you think this **post is useful**, I\'m happy if you **give a vote**. Any **questions or discussions are welcome!** Thank a lot.
[]