0
点赞
收藏
分享

微信扫一扫

LeetCode633.Sum of Square Number(Python)

爱做梦的老巫婆 2022-01-26 阅读 43

167的变形题,也是用两个指针

题解:

class Solution:
    def judgeSquareSum(self, c: int) -> bool:
        a = 0
        b = int(c ** 0.5)
        while a <= b:
            if a ** 2 + b ** 2 == c:
                return True
            elif a ** 2 + b ** 2 > c:
                b = b-1
            else:
                a = a +1
        return False

结果:

 

举报

相关推荐

0 条评论