[抄题]:

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. [QT]安装中出现的问题(安装qt5.8,出现Could not start:"{0,3010,1603,5100} msiexec ...")

    安装环境:win7/10 qt版本: qt-opensource-windows-x86-mingw530-5.8.0 在两台电脑上安装到 qt.tool.perl 的时候就弹出如图的窗口错误,开始以 ...

  2. 中 varStatus的属性简介

    varStatus是<c:forEach>jstl循环标签的一个属性,varStatus属性.就拿varStatus="status"来说,事实上定义了一个status ...

  3. Java中Set,List,Map的区别

    java集合的主要分为三种类型: Set(集) List(列表) Map(映射)   1.1 Collection接口 Collection是最基本的集合接口,声明了适用于JAVA集合(只包括Set和 ...

  4. rest_framework使用完之后的简单总结

    首先先大致概括一下使用流程,因为还不是对这个框架很熟悉(其实有很多知识可以对比formModel的) 其实还是遵循django的MTV的模式,还是得从url开始 1.rest_framework有一个 ...

  5. Python 中,字符串"连接"效率最高的方式是?一定出乎你的意料

    网上很多文章人云亦云,字符串连接应该使用「join」方法而不要用「+」操作.说前者效率更高,它以更少的代价创建新字符串,如果用「+」连接多个字符串,每连接一次,就要为字符串分配一次内存,效率显得有点低 ...

  6. egg 使用手记(一)

    1. 文件加载规则 引用官方的说法: 框架在加载文件时会进行转换,因为文件命名风格和 API 风格存在差异.我们推荐文件使用下划线,而 API 使用驼峰.比如 app/service/user_inf ...

  7. log4j及其log4j2的使用

    简单的说 log4j2 是log4j2的升级版,据说采用了一些新技术(无锁异步.等等),使得日志的吞吐量.性能比log4j 1.x提高10倍,并解决了一些死锁的bug,而且配置更加简单灵活.其使用方式 ...

  8. Flyway客户端使用

    一.flyway介绍 Flyway是一款开源的数据库版本管理工具,它更倾向于规约优于配置的方式.Flyway可以独立于应用实现管理并跟踪数据库变更,支持数据库版本自动升级,并且有一套默认的规约,不需要 ...

  9. git 基本操作 https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013744142037508cf42e51debf49668810645e02887691000

    1.创建版本库 (即仓库  repository)简单理解为一个目录,这个目录里的所有文件都可以被git管理起来,每个文件的修改删除,git都能跟踪,一边任何时刻都可以追踪历史,或者在将来某个时刻可以 ...

  10. java随机数组

    import java.util.Random; public class Ccore { public static void main(String[] args) { for(int i=1;i ...