Simple Java Solution | HashSet
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        int max = 0;\n        Set<Integer> set = new HashSet<>();\n        for(int i: nums) set.add(i);\n        for(int i=0;i<nums.length;i++) {\n            int num = nums[i];\n            int count = 1;\n            while(set.contains(num*num)) {\n                num = num*num;\n                count++;\n            }\n            if(count > 1 && count > max) max = count;\n        }\n        return max==0 ? -1 : max;\n    }\n}\n```
['Java']