阅读量:0
1. 题目
2. 分析
典型双指针的题了,不知道为啥LeetCode会把这题放到二分类别下?
需要知道math.ceil()
是向上取整;
3. 代码
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