Compartilhamento de tecnologia

【LeetCode】633.

2024-07-12

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

1. tema

2. Análise

Esta é uma pergunta típica de ponteiro duplo. Eu me pergunto por que o LeetCode coloca essa questão na categoria binária.

precisa sabermath.ceil()é arredondado;

3. Código

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