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 ...
随机推荐
- Linux centos7 shell 介绍、 命令历史、命令补全和别名、通配符、输入输出重定向
一.shell介绍 shell脚本是日常Linux系统管理工作中必不可少的,不会shell,就不是一个合格管理员. shell是系统跟计算机硬件交互使用的中间介质,一个系统工具.实际上在shell和计 ...
- 论STA | SOCV / POCV 之 variation (2)
芯片制造涉及到许多复杂重复的过程,如:光刻.蚀刻.离子注入.扩散.退火.而且都是原子级操作,尽管控制非常严格,但偏差不可避免. 工艺偏差会导致芯片物理参数偏差,如:线宽.沟道掺杂浓度.线厚.临界尺寸. ...
- dbGet net trace instant pin
proc rn { net_name } {puts " "puts "Net name : $net_name : "set name_rule [dbget ...
- allegro 16.6 铜皮显示问题
Setup-->User Preference-->display-->opengl-->staic-shapes_fill_solid打勾.可以将栅格铜皮改为实铜, Setu ...
- HTML5 canvas自制画板
找到一个画板的插件,很好用,点击下载 ,页面很简单,但是呢,貌似不适用于手机端,,,
- [代码记录] C语言链表
#开始 · 简单的创建链表 #代码 #include<conio.h> #include<stdio.h> #include<stdlib.h> struct St ...
- ExecutorService 的Future类
1.概述 在本文中,我们将了解Future.自Java 1.5以来一直存在的接口,在处理异步调用和并发处理时非常有用. 2.创建Future 简单地说,Future类表示异步计算的未来结果 - 这个结 ...
- python调用c++开发的动态库
此处列举一下python调用Windows端动态库. # *- coding=utf-8 -* import ctypes from ctypes import * import os objdll ...
- 数制的运用-CodeForces - 535B
题解: 因为每一位只可能是4或者7,可以类比二进制的思想. 基数为2,每一位的权值为2i-1:数字4表示的大小为1*2i-1:数字7表示的大小为2*2i-1. 将给定的n按照这种方法进行分解,求和.即 ...
- RTT学习之RTC设备
RTC: 目前系统内只允许存在一个 RTC 设备,且名称为 "rtc",所以不用查找设备 启用 Soft RTC (软件模拟 RTC),对无硬件RTC 启用 NTP 时间自动同步, ...