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: 3
Output: False

代码:

class Solution {
public:
bool judgeSquareSum(int c) {
for(int i = 0; i <= sqrt(c); i ++) {
if(i * i == c) return true;
int num = c - i * i;
int t = sqrt(num);
if(t * t == num) return true;
}
return false;
}
};

  

#Leetcode# 633. Sum of Square Numbers的更多相关文章

  1. [LeetCode] 633. Sum of Square Numbers 平方数之和

    Given a non-negative integer c, your task is to decide whether there're two integers a and b such th ...

  2. LeetCode 633. Sum of Square Numbers平方数之和 (C++)

    题目: Given a non-negative integer c, your task is to decide whether there're two integers a and b suc ...

  3. 【Leetcode_easy】633. Sum of Square Numbers

    problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明c ...

  4. 【LeetCode】633. Sum of Square Numbers

    Difficulty: Easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-n ...

  5. 【LeetCode】633. Sum of Square Numbers 解题报告(python & Java & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 列表生成式 循环 日期 题目地址:https ...

  6. 【leetcode】633. Sum of Square Numbers(two-sum 变形)

    Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c. ...

  7. 633. Sum of Square Numbers【Easy】【双指针-是否存在两个数的平方和等于给定目标值】

    Given a non-negative integer c, your task is to decide whether there're two integers a and bsuch tha ...

  8. 633. Sum of Square Numbers

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  9. 633. Sum of Square Numbers 是否由两个完全平方数构成

    [抄题]: Given a non-negative integer c, your task is to decide whether there're two integers a and b s ...

随机推荐

  1. shell 获取时间

    获取当前时间 t=$(date +"%Y-%m-%d %H-%M-%S") echo $t 获取前一天的当前时间 time=$(date -d "-1 day" ...

  2. 好系统重装助手教你清理win7系统中DNS缓存

    在我们使用电脑的过程中,有时候一个经常用的网页突然打不开了,遇到这种情况,清理一下DNS缓存就可以解决了.如何清理DNS缓存?小编这就给大家说一种最简单的方法. 1.组合键:win+R,输入cmd,点 ...

  3. UVA690-Pipeline Scheduling(dfs+二进制压缩状态)

    Problem UVA690-Pipeline Scheduling Accept:142  Submit:1905 Time Limit: 3000 mSec  Problem Descriptio ...

  4. python入门学习:3.操作列表

    python入门学习:3.操作列表 关键点:列表 3.1 遍历整个列表3.2 创建数值列表3.3 使用列表3.4 元组 3.1 遍历整个列表   循环这种概念很重要,因为它是计算机自动完成重复工作的常 ...

  5. [ZJOI2018]胖

    嘟嘟嘟 都说这题是送分题,但我怎么就不觉得的呢. 看来我还是太弱了啊-- 大体思路就是对于每一个设计方案,答案就是每一个关键点能更新的点的数量之和. 关键在于怎么求一个关键点能更新那些点. 首先这些点 ...

  6. Maven打包相关插件集合

    参考:https://www.cnblogs.com/selier/p/9510326.html

  7. 小a的轰炸游戏 (差分)

    我是看题解的! 这道题还是有很多细节,当然,是一道差分的好题! 题意:有2种飞机,一种是只炸上半菱形,一种是炸整个菱形.问所有区域内的所有格子的异或和. 思路:用前缀和思路: 这样遍历过去就完成了一次 ...

  8. a,b,c为3个整型变量,在不引入第四个变量的前提下写一个算法实现 a=b b=c c=a?(异或解决值互换问题)

    package com.Summer_0424.cn; /** * @author Summer * a,b,c为3个整型变量,在不引入第四个变量的前提下写一个算法实现 a=b b=c c=a? */ ...

  9. 测试工具使用-Qunit单元测试使用过程

    031302620 应课程要求写一篇单元测试工具的博客,但是暂时没用到java,所以不想使用junit(对各种类都不熟悉的也不好谈什么测试),原计划是要用phpunit,但是安装经历了三个小时,查阅各 ...

  10. 在Bootstrap开发中解决Tab标签页切换图表显示问题

    在做响应式页面的时候,往往需要考虑更多尺寸设备的界面兼容性,一般不能写死像素,以便能够使得界面元素能够根据设备的不同进行动态调整,但往往有时候还是碰到一些问题,如Tab标签第一页面正常显示,但是切换其 ...