2501.cpp (488B)
1 class Solution { 2 public: 3 int longestSquareStreak(vector<int> &nums) { 4 static int seen[100001]; 5 6 memset(seen, 0x00, sizeof(seen)); 7 sort(begin(nums), end(nums)); 8 9 int res = 0; 10 for (int i = 0; i < size(nums); i++) { 11 const int crnt = nums[i]; 12 if (crnt < 317) { 13 seen[crnt * crnt] = seen[crnt] + 1; 14 } 15 res = max(res, seen[crnt]); 16 } 17 18 return res ? res + 1 : -1; 19 } 20 };