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. C# FileSystemWatcher 并发

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  2. 使用VMware安装Ubuntu虚拟机,创建后开启显示黑屏的解决方法

    将使用的VMware-workstation-full-14.0.0.24051卸载改为使用VMware-workstation_full_12.1.1.6932. 安装VMware成功后,创建新的虚 ...

  3. fisher线性判别

    fisher 判决方式是监督学习,在新样本加入之前,已经有了原样本. 原样本是训练集,训练的目的是要分类,也就是要找到分类线.一刀砍成两半! 当样本集确定的时候,分类的关键就在于如何砍下这一刀! 若以 ...

  4. Tutorial 01_熟悉常用的Linux操作和Hadoop操作

    (一)熟悉常用的Linux 操作cd 命令:切换目录 (1) 切换到目录“/usr/local” (2) 切换到当前目录的上一级目录 (3) 切换到当前登录Linux 系统的用户的自己的主文件夹  ...

  5. pci设备驱动相关

    pci 设备注册及查找: https://www.cnblogs.com/image-eye/archive/2012/02/15/2352912.html PFN https://nieyong.g ...

  6. BugKu 这是一张单纯的图片

    http://123.206.87.240:8002/misc/1.jpg FLAG在哪里?? 吐槽一下这图片一点也不单纯 用010 打开后发现最后附着一段意义不明的字符,file命令也识别不出来 题 ...

  7. TsinsenA1221 大楼【矩阵快速幂】

    题目分析: 重新定义矩阵运算,$*$等价于$+$,$+$等价于$max$. 然后倍增一下,再二分一下. 代码: #include<bits/stdc++.h> using namespac ...

  8. wiki

    GRANT ALL PRIVILEGES ON confluence.* TO 'confluence'@'localhost' IDENTIFIED BY '%SaRK%TDpU#CyT6i';

  9. JavaScript与jQuery关于鼠标点击事件

    即实现鼠标点击其中一个菜单发生样式的改变,当点击下一个菜单时,当前菜单样式改变,其他菜单均变为之前样式. 用JavaScript,jQuery都可以实现,只是后者是封装的JavaScript库,具有s ...

  10. 【Sql Server】SQL SERVER 递归查询

    SQL SERVER 2005之前的版本只能用函数方法实现,SQL SERVER 2005之后新增了CTE功能,可以利用CTE实现递归查询: CTE:公用表达式Common Table Express ...