Problem · Sorting
Pythagorean Triple with Array Multiplicity
Learn this problemProblem statement
Given an integer array nums, return whether three distinct array occurrences can be chosen whose absolute values a, b, and c satisfy a * a + b * b = c * c.
- Negative signs do not affect the squared values.
- Equal absolute values may be reused only when the array contains enough separate occurrences.
Function
hasPythagoreanTriple(nums: int[]) → booleanExamples
Example 1
nums = [3,-4,5,8]return = trueThe distinct occurrences with absolute values 3, 4, and 5 satisfy 9 + 16 = 25.
Example 2
nums = [0,1,2]return = falseThe single zero cannot be paired with two occurrences having equal absolute value, and no other triple satisfies the equation.
Constraints
0 <= nums.length <= 2000.-1000000000 <= nums[i] <= 1000000000.