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. 排序学习实践---ranknet方法

    要: 1 背景      随着移动互联网的崛起,越来越多的用户开始习惯于从手机完成吃.喝.玩.乐.衣.食.住.行等各个方面的需求.打开手机,点开手淘.美团等APP,商品玲玲满目,而让用户将所有商品一页 ...

  2. 基于 WebGL 的 HTML5 楼宇自控 3D 可视化监控

    前言 智慧楼宇和人们的生活息息相关,楼宇智能化程度的提高,会极大程度的改善人们的生活品质,在当前工业互联网大背景下受到很大关注.目前智慧楼宇可视化监控的主要优点包括: 智慧化 -- 智慧楼宇是一个生态 ...

  3. React 特性剪辑(版本 16.0 ~ 16.9)

    Before you're going to hate it, then you're going to love it. Concurrent Render(贯穿 16) 在 18年的 JSConf ...

  4. 轻松测试 logstash 的配置文件

    配置文件本身非常脆弱!所以修改配置文件自然会引入部署失败的风险.如果能够对配置文件进行自动化测试将会极大的降低这种风险.本文将介绍一个可以自动化测试 logstash 配置文件的工具,让大家可以像写单 ...

  5. Python Revisited (变量)

    目录 = 浅拷贝 深拷贝` 函数的默认参数为可变类型时 危险 全局变量与临时变量 global 在函数里面进行复制 再看一个例子 numpy里的bug? 待续 @ 首先,需要指出的是,Python的变 ...

  6. jQuery文件分片上传

    前端代码: <input type="file" id="file6" multiple> <button type="button ...

  7. centos系统java后台运行(xshll关掉不至于jar程序结束)

    这样执行,就可以后台运行java程序 nohup java -Dfile.encoding=UTF-8 -jar xxx.jar  & 后台内容在该目录下nohup .out文件内,netst ...

  8. YCD 软件更新方法

    备份Messenger的数据库和Player的Chainmail数据 Upgrade process in Cnario is quite simple, uninstall old version ...

  9. mybatis 使用缓存策略

    mybatis中默认开启缓存 1.mybatis中,默认是开启缓存的,缓存的是一个statement对象. 不同情况下是否会使用缓存 同一个SqlSession对象,重复调用同一个id的<sel ...

  10. max-height、min-height、height优先级的问题

    前言 我们在实际开发中可能会限制元素的最大高度,那么我们使用的属性必定是max-height,那么不知道大家有没有考虑过如果同时设置max-height和height会发生什么呢? max-heigh ...