Problem statement

https://binarysearch.com/problems/Pythagorean-Triplets/

Solution

For each pair of elements find its sum of squares and check if it is in set of squares.

Complexity

It is O(n^2) for time and O(n) for space.

Code

class Solution:
    def solve(self, nums):
        nset = set(x*x for x in nums)
        for x, y in product(nums, nums):
            if x*x + y*y in nset:
                return True
        return False