https://leetcode-cn.com/problems/array-nesting/submissions/
我想我终于把这道题给做出来了:
public class Solution {
public int ArrayNesting(int[] nums) {
int res = 0;
if (nums.Length == 1) return 1;
var set = new HashSet<int>();
int c = 0;
while (true)
{
c= count(nums, c);
bool b = set.Add(nums[c]);
if (b)
{
res++;
}
else
{
break;
}
}
return res;
}
public static int count(int[] nums,int count)
{
return nums[count];
}
}
可我不明白为什么会有这样的这是用例:
解答错误
输入
[0,2,1]
输出
1
预期结果
2
难道 【0,2,1】的测试结果不是1么?