Java | HashSet
\n\n# Code\njava []\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        Set<Long> set = new HashSet<>();\n        for (int num : nums)\
\n\n# Code\n```java []\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        Set<Long> set = new HashSet<>();\n        for (int num : nums)\n            set.add((long) num);\n\n        Arrays.sort(nums);\n        int res = -1;\n\n        for (int num : nums) {\n            long temp = (long) num;\n            int cnt = 1;\n            while (set.contains(temp * temp)) {\n                cnt++;\n                temp = temp * temp;\n                res = Math.max(res, cnt);\n            }\n        }\n        return res;\n    }\n}\n```
['Java']