Given a non-negative integer c, your task is to decide whether there're two integers a and bsuch that a2 + b2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5 Example 2: Input: 3 Output: False Accepted 38,694 Submissions 117,992  …
problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明c就是个平方数,只要再凑个0,就是两个平方数之和,返回 true:如果不等于的话,那么算出差值 c - i*i,如果这个差值也是平方数的话,返回 true.遍历结束后返回 false, class Solution { public: bool judgeSquareSum(int c) { ; --…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 列表生成式 循环 日期 题目地址:https://leetcode.com/problems/sum-of-square-numbers/discuss/ 题目描述 Given a non-negative integer c, your task is to decide whether there're two integers a an…
Difficulty: Easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-numbers/submissions/ Given a non-negative integer c, your task is to decide whether there're two integers aand b such that a2 + b2 = c. Example 1: Inpu…
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*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 >…
https://leetcode.com/problems/sum-of-square-numbers/ 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:…
题目: 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,使…
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { public: bool judgeSquareSum(int c) { ,b=sqrt(c); while(a<=b) { int k=a*a+b*b; if(k==c) return true; else if(k>c) b--; else a++; } return false; } }; 数学方法…
[抄题]: 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 [暴力解法]: 时间分析: 空间分析:n^2 [优化后]:…