#Leetcode# 633. Sum of Square Numbers
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的更多相关文章
- [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 ...
- 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 ...
- 【Leetcode_easy】633. Sum of Square Numbers
problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明c ...
- 【LeetCode】633. Sum of Square Numbers
Difficulty: Easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-n ...
- 【LeetCode】633. Sum of Square Numbers 解题报告(python & Java & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 列表生成式 循环 日期 题目地址:https ...
- 【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. ...
- 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 ...
- 633. Sum of Square Numbers
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- 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 ...
随机推荐
- 【算法】LeetCode算法题-Longest Common Prefix
这是悦乐书的第146次更新,第148篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第5题(顺位题号是14),给定一个随机的字符串数组,查找这些字符串元素的公共前缀字符串, ...
- Linux 小知识翻译 - 「SCP和SFTP」
这次想说说「SCP和SFTP」. 不管SCP还是SFTP,都是SSH的功能之一.都是使用SSH协议来传输文件的. 不用说文件内容,就是登录时的用户信息都是经过SSH加密后才传输的,所以说SCP和SFT ...
- 【夯实PHP基础】PHP多进程-- pcntl_fork实现
本文地址 参考文档 分享提纲: 1. 概述 2.安装(只支持Linux) 3. 代码实验多进程pcntl_fork 4. 具体解释 1. 概述 PHP有个pcntl_fork的函数可以实现多进程,但要 ...
- Django forms 关于select和checkbox设置初始选中值
Django的forms和models一样很牛逼.他有两种功能,一是生成form表单,还有就是form表单的验证. 这里主要说一下生成form表单时经常用到的需要设置 初始值 / 默认值 的情况. 1 ...
- 1.tushare模块的应用
tushare模块的应用 今日概要 TuShare简介和环境安装 TuShare的应用 今日详情 一.TuShare简介和环境安装 TuShare是一个著名的免费.开源的python财经数据接口包.其 ...
- Nginx的configure各项中文说明
–prefix=<path> – Nginx安装路径.如果没有指定,默认为 /usr/local/nginx. –sbin-path=<path> – Nginx可执行文件安装 ...
- Session的生命周期之关于浏览器关闭后的Session
Session是JSP的九大内置对象中的一个,它可以保存当前用户的各种的状态信息. 初次接触Session时认为Session的生命周期是从浏览器打开一个窗口发送请求开始,到浏览器窗口关闭结束.其实这 ...
- Linux之文件属性
文件属性是什么? [root@luffy_boy-001 /]# ls -lhi /etc/hosts 129822 -rw-r--r--. 2 root root 198 Jan 11 2019 / ...
- CSAPP:第八章 异常控制流1
CSAPP:第八章 异常控制流1 关键点:异常 8.1 异常8.2 进程 现代系统通过使控制流发生突变来对这些情况做出反应,一般而言,我们把这些突变称为异常控制流(Exceptional Cont ...
- jsonp跨域实现单点登录,跨域传递用户信息以及保存cookie注意事项
网站A:代码:网站a的login.html页面刷新,使用jsonp方式将信息传递给b.com的login.php中去,只需要在b.com中设置一下跨域以及接收参数,然后存到cookei即可, 注意:网 ...