Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 938 Bytes

File metadata and controls

45 lines (32 loc) · 938 Bytes

663. Question 663

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 : N/A

Acceptance Rate : Unknown


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