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 = 5
Return true // 1 * 1 + 2 * 2 = 5

Given n = -5
Return false

代码

 class Solution {
public:
/*
* @param : the given number
* @return: whether whether there're two integers
*/
bool checkSumOfSquareNumbers(int num) {
// write your code here
if (num < ) {
return false;
}
int c = floor(sqrt(num));
int i = c;
if (i * i == num) return true;
int j = ;
while (j <= i) {
if (i * i + j * j == num) {
return true;
} else if (i * i + j * j < num) {
j++;
} else {
i--;
}
}
return false;
}
};

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

  1. 【Leetcode_easy】633. Sum of Square Numbers

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

  2. [LeetCode] 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 ...

  3. 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 ...

  4. [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 ...

  5. 【LeetCode】633. Sum of Square Numbers

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

  6. LeetCode633. Sum of Square Numbers(双指针)

    题意:给定一个非负整数c,确定是否存在a和b使得a*a+b*b=c. class Solution { typedef long long LL; public: bool judgeSquareSu ...

  7. C#LeetCode刷题之#633-平方数之和( Sum of Square Numbers)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3885 访问. 给定一个非负整数 c ,你要判断是否存在两个整数 ...

  8. [Swift]LeetCode633. 平方数之和 | 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 ...

  9. LeetCode算法题-Sum of Square Numbers(Java实现)

    这是悦乐书的第276次更新,第292篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第144题(顺位题号是633).给定一个非负整数c,判断是否存在两个整数a和b,使得a的 ...

随机推荐

  1. 【luogu P1351 联合权值】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1351 做了些提高组的题,不得不说虽然NOIP考察的知识点虽然基本上都学过,但是做起题来还是需要动脑子的. 题 ...

  2. linux 重启 启动 apache服务

    如何使用service  httpd restart,不成功的话,直接去apache文件目录里去找可执行文件,执行启动. 一般apache目录 ./usr/local/httpd/bin ,在bin目 ...

  3. [译]React如何区别class和function

    原文 How Does React Tell a Class from a Function? 译注: 一分钟概览-- React最后采用了在React.Component上加入isReactComp ...

  4. MySQL优化之Explain命令解读

    简述: explain为mysql提供语句的执行计划信息.可以应用在select.delete.insert.update和place语句上.explain的执行计划,只是作为语句执行过程的一个参考, ...

  5. 一文读懂类加载机制--ClassLoader

    一.什么是ClassLoader? 大家都知道,当我们写好一个Java程序之后,不是管是CS还是BS应用,都是由若干个.class文件组织而成的一个完整的Java应用程序,当程序在运行时,即会调用该程 ...

  6. Spring入门第一课:Spring基础与配置Bean

    1.入门 Spring是简化java开发的一个框架,其中IoC和AOP是Spring的两个重要核心.由于Spring是非侵入性的,通过Ioc容器来管理bean的生命周期,还整合了许多其他的优秀框架,所 ...

  7. html中的居中问题

    1.表格居中:<table>标签的align属性 <table align="center">...... </table> 2.表格内容居中; ...

  8. python多线程知识-实用实例

    python多线程使用场景:IO操作,不适合CPU密集操作型任务   1.多个线程内存共享 2.线程同时修改同一份数据需要加锁,mutex互斥锁 3.递归锁:多把锁,锁中有锁 4.python多线程, ...

  9. 12种开源Web安全扫描程序

    转自:https://blog.csdn.net/wh211212/article/details/78620963 赛门铁克的一个有趣的报告显示,76%的被扫描网站有恶意软件 如果您使用的是Word ...

  10. 【读书笔记 - Effective Java】03. 用私有构造器或者枚举类型强化Singleton属性

    实现Singleton(代表本质上唯一的系统组件)的三种方法: 1. 保持私有构造器,导出公有的静态成员,客户端访问该类的唯一实例. 2. 保持私有构造器,公有的成员是静态工厂方法. 3. 单元素的枚 ...