[抄题]:

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

[暴力解法]:

时间分析:

空间分析:n^2

[优化后]:

时间分析:

空间分析:n

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

以为同向型,其实对撞型,关键是能省空间 面试官喜欢

[一句话思路]:

对撞型,关键是能省空间 面试官喜欢

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

  1. while (i <= (int)Math.sqrt(c) && j >= 0)  有没有等号,还是需要写完了试试

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

对撞型省时间

[复杂度]:Time complexity: O(n) Space complexity: O(1)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

class Solution {
public boolean judgeSquareSum(int c) {
//cc
if (c < 0) return false; //ini
int i = 0, j = (int)Math.sqrt(c); //while loop
while (i <= (int)Math.sqrt(c) && j >= 0) {
if (i * i + j * j < c) i++;
else if (i * i + j * j > c) j--;
else return true;
} return false;
}
}

[代码风格] :

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

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

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

  5. 【LeetCode】633. Sum of Square Numbers

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

  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. 【LeetCode】633. Sum of Square Numbers 解题报告(python & Java & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 列表生成式 循环 日期 题目地址:https ...

  8. #Leetcode# 633. Sum of Square Numbers

    https://leetcode.com/problems/sum-of-square-numbers/ Given a non-negative integer c, your task is to ...

  9. 633. Sum of Square Numbers

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

随机推荐

  1. html中<video>显示视频的时候,MP4的格式问题

    html支持的视频格式:HTML5视频 注意 浏览器对mp4 的编码方式要求的非常严格 视频编码必须是H.264 音频编码必须是: AAC

  2. c++ 基础知识 0001 const 知识2

    1.const修饰函数返回值 (1)指针传递 如果返回const data,non-const pointer,返回值也必须赋给const data,non-const pointer.因为指针指向的 ...

  3. svn的使用流程

    一.安装: 1. 服务器端:VisualSVN_Server 2. 客户端:TortoiseSVN 二.使用VisualSVN Server建立版本库 1. 首先打开VisualSVN Server ...

  4. Laraver 框架资料

    重定向: return redirect()->to('http://www.baidu.com'); 重定向到内部路由 return redirect()->route(‘name’); ...

  5. PHPCMS V9调用父栏目 顶级父栏目的代码

    一.调用父栏目 首先是列表页和二级栏目页list.html {$CATEGORYS[$top_parentid][catname]} //顶级父栏目名称 {$CATEGORYS[$CAT[parent ...

  6. 老师木发的makefile与autotools

    makefile http://scc.qibebt.cas.cn/docs/linux/base/%B8%FA%CE%D2%D2%BB%C6%F0%D0%B4Makefile-%B3%C2%F0%A ...

  7. Block Towers (思维实现)

    个人心得:这题没怎么看,题意难懂.后面比完再看的时候发现很好做但是怎么卡时间是个问题. 题意:就是有m个可以用2层积木的,n个可以用三层积木的,但是他们不允许重复所以可以无限添加. 比如 3 2 一开 ...

  8. jQuery火箭图标返回顶部代码

    在网上找来段使用jQuery火箭图标返回顶部代码,感觉比较酷,比较炫,大概样式如下, 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. ...

  9. VC++ MFC SQL ADO数据库访问技术使用的基本步骤及方法

    1.首先,要用#import语句来引用支持ADO的组件类型库(*.tlb),其中类型库可以作为可执行程序 (DLL.EXE等)的一部分被定位在其自身程序中的附属资源里,如:被定位在msado15.dl ...

  10. layui与layer同时引入冲突的问题

    之前在项目中只有用layer,但是后来有用到了layui,结果发现同时引入这两个东东 会出现冲突的问题 导致代码运行不正常 后来网上找到了解决办法: 学习源头:http://fly.layui.com ...