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. 设置SSH免密码登录

    1.cd .ssh 2.执行下面的命令,三次回车. ssh-keygen -t rsa cat id_rsa.pub >> authorized_keys 3.发送公钥 scp .ssh/ ...

  2. LeetCode算法题-Find the Difference(Java实现-五种解法)

    这是悦乐书的第214次更新,第227篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第82题(顺位题号是389).给定两个字符串s和t,它们只包含小写字母.字符串t由随机混 ...

  3. LeetCode算法题-Remove Linked List Elements(Java实现)

    这是悦乐书的第189次更新,第191篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第48题(顺位题号是203).移除单链表中节点值为val的节点.例如: 输入:1-> ...

  4. 【大数据技术】HBase介绍

    1.HBase简介1.1 Hbase是什么HBase是一种构建在HDFS之上的分布式.面向列.多版本.非关系型的数据库,是Google Bigtable 的开源实现. 在需要实时读写.随机访问超大规模 ...

  5. MySQL高级知识(六)——索引优化

    前言:索引优化的目的主要是让索引不失效,本篇通过相关案例对索引优化进行讲解. 0.准备 创建经典的tb_emp表. DROP TABLE IF EXISTS `tb_emp`; CREATE TABL ...

  6. 在Intellij IDEA中使用Maven的方式将项目导出为jar包

    前言:由于项目使用maven管理方式,所以在未发布版本的时候,就需要将项目打成jar包,供本地调试使用.注意在使用本地jar包的时候,需要将pom文件中相关jar包的依赖屏蔽,再将jar包加入项目中. ...

  7. WPF窗体の投影效果

    有时候我们需要给WPF窗体加上一个毛边(投影效果) 我们可以在窗体下加上如下代码 <Window.Effect> <DropShadowEffect BlurRadius=" ...

  8. Python学习之装饰器进阶

    函数知识回顾: 函数的参数分为:实参和形参. 实参:调用函数的时候传入的参数: 形参:分为3种(位置参数.默认参数.动态传参) 位置参数:必须传值 def aaa(a,b): print(a,b) a ...

  9. UVA1626-Brackets sequence(动态规划基础)

    Problem UVA1626-Brackets sequence Time Limit: 4500 mSec Problem Description Input The input begins w ...

  10. 转://Oracle 数据备份与恢复微实践

    1.模拟控制文件丢失后的数据库恢复(完全恢复) 今天的主题是备份与恢复,目的就是保护数据的安全性,众所周知Oracle之所以在市场上占据了50%的份额,与它提供了强大的数据保护措施是分不开的,下面我们 ...