class Solution {
public:
bool isPerfectSquare(int num) {
/*
//方法一:蜜汁超时……
if (num < 0) return false;
if (num == 1) return true;
for (int i=1;i*i<=num;i++){
if (i*i==num)
return true;
}
return false;
}*/ /*
//方法二:是对的!
if(num < 0) return false;
if(num == 1) return true;
for(int i = 1; i<= num/i;i++){
if(i*i == num) return true;
}
return false;
} */
//方法三:值得学习的【二分查找】
if (num < ) return false;
if (num == ) return true;
int left = ; //注意!
int right = num/; //注意!
long mid;
long val;
while (left <= right){
mid = (left + right)/;
val = mid * mid;
if (val == num) return true;
else if (val > num) right = mid - ;
else left = mid + ;
}
return false;
} };

【easy】367. Valid Perfect Square 判断是不是平方数的更多相关文章

  1. 367. Valid Perfect Square判断是不是完全平方数

    [抄题]: Given a positive integer num, write a function which returns True if num is a perfect square e ...

  2. [LeetCode]367. Valid Perfect Square判断完全平方数

    方法有很多,我觉得比较容易记住的是两个,一个是二分法,在1-num/2中寻找目标数 另一个是数学方法: public boolean isPerfectSquare(int num) { /* 有很多 ...

  3. 367. Valid Perfect Square

    原题: 367. Valid Perfect Square 读题: 求一个整数是否为完全平方数,如1,4,9,16,……就是完全平方数,这题主要是运算效率问题 求解方法1:812ms class So ...

  4. [LeetCode] 367. Valid Perfect Square 检验完全平方数

    Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...

  5. 【LeetCode】367. Valid Perfect Square 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:完全平方式性质 方法二:暴力求解 方法三:二 ...

  6. 【leetcode】367. Valid Perfect Square

    题目描述: Given a positive integer num, write a function which returns True if num is a perfect square e ...

  7. Leetcode 367. Valid Perfect Square

    Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...

  8. [leetcode]367. Valid Perfect Square验证完全平方数

    Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...

  9. [LC] 367. Valid Perfect Square

    Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...

随机推荐

  1. FileMode文件模式(转载)

    FileMode指定操作系统打开文件的方式. Append 6 若存在文件,则打开该文件并查找到文件尾,或者创建一个新文件. 这需要 Append 权限. FileMode.Append 只能与 Fi ...

  2. HNOI2019:My Dream

    反正这次的目标也不是进省队,目标就是做到最好吧-- 下面都是流水账~ Day -INF ~ Day -3 专题交流没什么好说的,模拟赛详见3.11-3.27省选前多校联考乱记和3.28-4.2CJ大毒 ...

  3. iview inoput type=textarea 禁止拉伸

    设置 :maxRows.minRows相同即可 <Input v-model="formValidate.remark" type="textarea" ...

  4. (hdu 6024) Building Shops

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6024 Problem Description HDU’s n classrooms are on a ...

  5. auth mysql

    DROP TABLE IF EXISTS tky_auth_role;CREATE TABLE tky_auth_role ( roleid MEDIUMINT (8) UNSIGNED NOT NU ...

  6. 采用VSPD、ModbusTool模拟串口、MODBUS TCP设备进行Python采集软件开发

    版权声明:本文为博主原创文章,欢迎转载,并请注明出处.联系方式:460356155@qq.com 不少仪器/设备都提供了数据采集的接口,其中不少是串口或网络的MODBUS/TCP协议. 串口是比较简单 ...

  7. 从源码看springboot默认的资源文件和配置文件所在位置

    首先,使用的springboot版本是2.X,在这里写一点学习springboot的记录 springboot需要配置的不多,但也并不是完全不需要配置就可以顺畅使用,这里看一下它默认的配置 首先,看一 ...

  8. MySQL之InnoDB数据页结构(转自掘金小册 MySQL是怎样运行的,版权归作者所有!)

    InnoDB为了不同的目的而设计了不同类型的页,我们把用于存放记录的页叫做数据页. 一个数据页可以被大致划分为7个部分,分别是 File Header,表示页的一些通用信息,占固定的38字节. Pag ...

  9. Python——正则模块

    1.re模块是用来操作正则表达式 2.正则表达式——用来字符串匹配的 (1)字符组:[字符组]  例如[0123fdsa456*/-] [0-9] 等同于[0123456789] [a-z] 匹配小写 ...

  10. 8.docker的安全性

    在查看Docker安全性时,有四个主要方面需要考虑: 内核的内在安全性及其对命名空间和cgroup的支持; Docker守护进程本身的攻击面; 容器配置配置文件中的漏洞,默认情况下或用户自定义时. 内 ...