You are given a 0-indexed integer array nums of length n, where all integers are in [0, n-1] and each value appears exactly once. A set S is formed starting at i, adding nums[i], nums[nums[i]], etc., until you revisit an index. Return the longest such set S.
Input: A permutation array nums of length n (0-indexed, distinct values in [0,n-1]).
Output: Integer — length of the longest cycle.
Input: [5,4,0,3,1,6,2]
Output: 4
Explanation: Starting at 0: 0→5→6→2→0. Cycle length 4.Input: [0,1,2,3,4,5,6]
Output: 1
Explanation: Each element points to itself. Longest cycle = 1.Input: [1,0,3,2]
Output: 2
Explanation: 0→1→0 (length 2) and 2→3→2 (length 2).1<=nums.length<=10^50<=nums[i]<nums.lengthAll values distinct.