lintcode: Check Sum of Square Numbers】的更多相关文章

Check Sum of Square Numbers Given a integer c, your task is to decide whether there're two integers a and b such that a^2 + b^2 = c. 您在真实的面试中是否遇到过这个题? Yes 样例 Given n = 5Return true // 1 * 1 + 2 * 2 = 5 Given n = -5Return false 代码 class Solution { pub…
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) { ; --…
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 这道题让我们求一个数是否能由平方数之和组成,刚开始博主没仔细看题,没有看…
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  …
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 这道题让我们求一个数是否能由平方数之和组成,刚开始博主没仔细看题,没有看…
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…
题意:给定一个非负整数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://www.byteflying.com/archives/3885 访问. 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 输入: 3 输出: False Given a non-negative integer c, your task is to decide whether there're two…
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…
这是悦乐书的第276次更新,第292篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第144题(顺位题号是633).给定一个非负整数c,判断是否存在两个整数a和b,使得a的平方与b的平方之和等于c.例如: 输入:5 输出:true 说明:1 x 1 + 2 x 2 = 5 输入:3 输出:false 本次解题使用的开发工具是eclipse,jdk使用的版本是1.8,环境是win7 64位系统,使用Java语言编写和测试. 02 第一种解法 暴力解法,直接使用两层for…