Skip to content

Commit

Permalink
Time: 153 ms (6.25%), Space: 64.6 MB (5.56%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Oct 28, 2024
1 parent 09e956f commit e552a99
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public int longestSquareStreak(int[] nums) {
TreeSet<Integer> set = new TreeSet<>();
for(int num : nums) {
set.add(num);
}

int ans = 1;
while(!set.isEmpty()) {
int curr = set.first();
int streak = 0;
while(!set.isEmpty() && set.contains(curr)) {
set.remove(curr);
curr = curr * curr;
streak++;
}
ans = Math.max(streak, ans);
}
return ans == 1 ? -1 : ans;
}
}

0 comments on commit e552a99

Please sign in to comment.