C# 代码
public class Solution {
public int LongestSquareStreak(int[] nums) {
HashSet<int> set = nums.ToHashSet<int>();
int result = 0;
foreach (int i in set){
int ans = 0;
int temp = i;
while (set.Contains(temp)){
ans++;
if (temp > 1000) break;
temp *= temp;
}
result = Math.Max(result, ans);
}
return result < 2 ? -1 : result;
}
}