Technology sharing

LeetCode】 DCXXXIII

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

1. topic

2. Analysis

Haec quaestio duplex regula typica est. Miror cur LeetCode hanc quaestionem sub categoria binaria ponit?

opus est sciremath.ceil()rotundata;

3. Code

class Solution:
    def judgeSquareSum(self, c: int) -> bool:
        upper = math.ceil(sqrt(c))
        print(upper)
        left, right = 0, upper
        while(left <= right):
            if left * left + right * right > c:
                right-=1
            elif left * left + right * right < c:
                left+=1
            else:
                return True
        return False
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13