Java 代码如下: public boolean judgeSquareSum(int c) { int left = 0; int right = (int) Math.sqrt(c); while(left <= right){ int sum = left * left + right * right; if(sum < c) left++; else if(sum > c) right--; else {
Can you solve this real interview question? Sum of Square Numbers - Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: c = 5 Output: true Explanation: 1 * 1 + 2 * 2 = 5 Example 2:
https://leetcode.com/problems/sum-of-square-numbers/discuss/104932/hashset-java-quick-solution-one-for-loop LeetCode All in One 题目讲解汇总(持续更新中...)
classSolution {public:booljudgeSquareSum(intc) {if(c ==0)returntrue;inti =sqrt(c);while(i) {intx = c - i *i;intt =sqrt(x);if(t * t ==x)returntrue; i--; }returnfalse; } }; // 6 ms
LeetCode-Sum of Square Numbers Description: 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...
633. Sum of Square Numbers ...【java】633. Sum of Square Numbers 问题原文https://leetcode-cn.com/problems/sum-of-square-numbers/description/ 解决这道题的过程中,了解到完全平方数的一个性质,在这里记录一下 有关问题代码如下,时间复杂度为lgn ......
class Solution { public boolean judgeSquareSum(int c) { int i = 0, j = (int)Math.sqrt(c); while(i <= j) { int sum = i*i + j*j; if(sum == c) { return true; } else if(sum > c) { j--; } else { i++; } } return false; } }来源...
Example 1: Input:5Output:TrueExplanation:1*1+2*2=5 1. 2. 3. Example 2: Input:3Output:False 1. 2. 方法一:两遍for循环, 复杂度o(n2), 会time limit 报错 public boolean judgeSquareSum(int c) { for(int i=0;i<=c;i++) { ...
Sum of Square Numbers 2. Solution 代码语言:javascript 代码运行次数:0 运行 classSolution{public:booljudgeSquareSum(int c){int root=int(sqrt(c))+1;for(int i=0;i<root;i++){int difference=c-i*i;int j=int(sqrt(difference));if(i*i+j*j==c){returntrue;}}returnfalse;}};...
2657-find-the-prefix-common-array-of-two-arrays.cpp 2707-extra-characters-in-a-string.cpp csharp dart go java javascript kotlin python ruby rust scala swift typescript .gitignore .prettierrc .problemSiteData.json CONTRIBUTING.md LICENSE Neetcode-update.iml README.md README_template.md update...