C++ | Simple Map and Sorting
Approach\nStore value, and sort the given vector.\nChecking longest Square Streak one by one and erase the number in map.\n\nThe range of nums[i] is small, so w
## Approach\nStore value, and sort the given vector.\nChecking longest Square Streak one by one and erase the number in map.\n\nThe range of ```nums[i]``` is small, so we can simply use vector instead of unordered_map.\n\n## Code\n```\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n\n        vector<int> vis(1e5 + 1, 0);\n        // build map\n        for (const auto &i : nums)\n            ++vis[i];\n\n        sort(nums.begin(), nums.end());\n        int ans = -1, cnt = 0, n = nums.size();\n\n        for (int i = 0, len = 0; i < n && cnt < n; ++i, len = 0) {\n            \n            if (!vis[nums[i]])\n                continue;\n\n            for (long now = nums[i]; now <= 1e5 && vis[now]; \n                ++len, vis[now] = 0, now *= now);\n\n            // update valid ans\n            if (len > 1)\n                ans = max(ans, len);\n\n        }\n\n        return ans;\n    }\n};\n```\n**Upvote** if you like this post : )
['Hash Table', 'Sorting', 'C++']