[C++|Java|Python3] dp
Please pull this commit for solutions of weekly 323. \n\nIntuition\nIt is quite strange that sorting is allowed in this problem. However, since sorting is allow
Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/8f409c5e220a4a1a1d7fdfbfcc1dcd24eeead232) for solutions of weekly 323. \n\n**Intuition**\nIt is quite strange that sorting is allowed in this problem. However, since sorting is allowed, all that matters is whether a squared number exists. One solution via DP is to check if a number x is a squared number if so its streak is 1+dp[r] where r is the square root of x. \n\n**Implementation**\n**C++**\n```\nclass Solution {\npublic:\n    int longestSquareStreak(vector<int>& nums) {\n        vector<int> dp(100\'001); \n        sort(nums.begin(), nums.end()); \n        for (auto& x : nums) {\n            dp[x] = max(1, dp[x]); \n            int v = sqrt(x); \n            if (v * v == x) dp[x] = 1 + dp[v]; \n        }\n        int ans = *max_element(dp.begin(), dp.end()); \n        return ans > 1 ? ans : -1; \n    }\n};\n```\n**Java**\n```\nclass Solution {\n    public int longestSquareStreak(int[] nums) {\n        int[] dp = new int[100_001]; \n        Arrays.sort(nums); \n        int ans = 0; \n        for (int x : nums) {\n            dp[x] = Math.max(1, dp[x]); \n            int v = (int) Math.sqrt(x); \n            if (v*v == x) dp[x] = 1 + dp[v]; \n            ans = Math.max(ans, dp[x]); \n        }\n        return ans > 1 ? ans : -1; \n    }\n}\n```\n**Python3**\n```\nclass Solution:\n    def longestSquareStreak(self, nums: List[int]) -> int:\n        dp = defaultdict(int)\n        for x in sorted(nums): \n            dp[x] = max(dp[x], 1)\n            v = isqrt(x)\n            if v**2 == x: dp[x] = 1 + dp[v]\n        ans = max(dp.values())\n        return ans if ans > 1 else -1\n```\n**Complexity**\nTime `O(NlogN)`\nSpace `O(N)`
['C', 'Java', 'Python3']