Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.1 KB

_663. Equal Tree Partition.md

File metadata and controls

45 lines (32 loc) · 1.1 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 17, 2024

Last updated : June 17, 2024


Related Topics : Tree, Depth-First Search, Binary Tree

Acceptance Rate : 41.59 %


Solutions

Python

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