leetcode633】的更多相关文章

Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5  Example 2: Input: 3 Output: False 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a…
用开方的思想来解题. bool judgeSquareSum(int c) { int h = pow(c, 0.5); ; i <= h; i++) { ), 0.5); if (left - int(left) == 0.0) { return true; } } return false; } 补充一个phthon的实现,使用双指针思想: class Solution: def judgeSquareSum(self, c: int) -> bool: i=0 j=int(c ** 0.…
给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 示例2: 输入: 3 输出: False 方法一: class Solution { public: bool judgeSquareSum(int c) { for(int i = sqrt(c); i >= 0; i--) { int j = sqrt(c - i * i); if(i * i + j * j ==…
题意:给定一个非负整数c,确定是否存在a和b使得a*a+b*b=c. class Solution { typedef long long LL; public: bool judgeSquareSum(int c) { LL head = 0; LL tail = (LL)(sqrt(c)); while(head <= tail){ LL sum = head * head + tail * tail; if(sum == (LL)c) return true; else if(sum >…
上篇文章中一道数学问题 - 自除数,今天我们接着分析 LeetCode 中的另一道数学题吧~ 今天要给大家分析的面试题是 LeetCode 上第 633 号问题, Leetcode 633 - 平方数之和 https://leetcode.com/problems/sum-of-square-numbers/ 题目描述 给定一个非负整数 c ,你要判断是否存在两个整数 a和 b,使得 \(a^2 + b^2 = c\). 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2…