663. Equal Tree Partition
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 17, 2024
Last updated : June 17, 2024
Related Topics : Tree, Depth-First Search, Binary Tree
Acceptance Rate : 41.59 %
class Solution:
def judgeSquareSum(self, c: int) -> bool:
cRoot = ceil(c ** .5)
valsUpTo = [x ** 2 for x in range(cRoot + 1)]
left, right = 0, len(valsUpTo) - 1
while left < right :
summ = valsUpTo[left] + valsUpTo[right]
if summ > c :
right -= 1
elif summ < c :
left += 1
else :
return True
return 2 * valsUpTo[left] == c