LeetCode633. Sum of Square Numbers(双指针)
题意:给定一个非负整数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 > (LL)c) --tail;
else ++head;
}
return false;
}
};
LeetCode633. Sum of Square Numbers(双指针)的更多相关文章
- Leetcode633.Sum of Square Numbers平方数之和
给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 示例2: 输入: 3 ...
- 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 ...
- 【Leetcode_easy】633. Sum of Square Numbers
problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明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 ...
- [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 ...
- [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 ...
- LeetCode算法题-Sum of Square Numbers(Java实现)
这是悦乐书的第276次更新,第292篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第144题(顺位题号是633).给定一个非负整数c,判断是否存在两个整数a和b,使得a的 ...
- [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
Difficulty: Easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-n ...
随机推荐
- qxdm,qpst,qcat抓包分析VoLTE SIP协商包
QXDM,QPST和QCAT是Qualcomm高通公司针对高通芯片的抓包分析工具. QXDM抓包分析,QPST与手机com口连接,QCAT用来分析抓包产生的isf文件(log). 使用版本: QXDM ...
- Vue-路由跳转的几种方式和路由重定向
一.标签路由 router-link 注意:router-link中链接如果是'/'开始就是从根路由开始,如果开始不带'/',则从当前路由开始. 1.不传参 <router-link :to=& ...
- Python学习之函数篇
python查看对象,函数帮助文档:.__doc__,例:str.split.__doc__ 查看详细对象,函数文档:help(),例:help(str.split) 函数参数可设置默认值 如果不能提 ...
- Error: EACCES: permission denied, open '/Users/qinmengjiao/WebstormProjects/m-kbs-app/.babelrc
表示没有访问这个文件的权限 执行命令 sudo chown -R $(whoami) ~/WebstormProjects/m-kbs-app/.babelrc 就可以解决上面的问题 以下是chown ...
- casperJs的安装
自己买了vps就是爽,想装什么就装什么.就比如说casperjs 1.首先需要安装它的运行环境phantomjs *将这个git项目clone到自己的vps上[https://github.com/a ...
- C:产生随机数
函数说明 #include <time.h> time_t time(time_t *t); 功能:获取当前系统时间 参数:常设置为NULL 返回值:当前系统时间, time_t 相当于l ...
- 【Math】高数-一个有趣的旋转体体积与面积
Go confidently in the direction of your dreams. Live the life you've imagined. 题目 设曲线 \(y = \tfrac{1 ...
- 吴裕雄 python 人工智能——基于神经网络算法在智能医疗诊断中的应用探索代码简要展示
#K-NN分类 import os import sys import time import operator import cx_Oracle import numpy as np import ...
- mcast_get_loop函数
#include <errno.h> #include <net/if.h> #include <sys/socket.h> #include <netine ...
- P1598
无语的是,我以为题目条件的‘在任何一行末尾不要打印不需要的多余空格’意思是每一行都只能到最后一个 '*' 出现就换行,然后用了 '\b',结果怎么都不过,于是看了题解,发现别人都没管这个 = =!!, ...