Typical binary search.. but take care of data overflow if you are using C++

class Solution {
public:
bool isPerfectSquare(int num) {
if(num < ) return false;
if(num < ) return true; long long i = , j = num - ;
while(i <= j)
{
long long mid = (i + j) / ;
long long r = mid * mid; if(r == num) return true;
if(r < num) i = mid + ;
else j = mid - ;
}
return false;
}
};

LeetCode "Valid Perfect Square"的更多相关文章

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

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

  2. Leetcode之二分法专题-367. 有效的完全平方数(Valid Perfect Square)

    Leetcode之二分法专题-367. 有效的完全平方数(Valid Perfect Square) 给定一个正整数 num,编写一个函数,如果 num 是一个完全平方数,则返回 True,否则返回 ...

  3. LeetCode_367. Valid Perfect Square

    367. Valid Perfect Square Easy Given a positive integer num, write a function which returns True if  ...

  4. 367. Valid Perfect Square

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

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

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

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

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

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

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

  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. 【leetcode】367. Valid Perfect Square

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

随机推荐

  1. Centos 安装 neo4j

    This is experimental and not considered safe for production. You have been warned. Please note that ...

  2. java并发编程-Executor框架

    Executor框架是指java 5中引入的一系列并发库中与executor相关的一些功能类,其中包括线程池,Executor,Executors,ExecutorService,Completion ...

  3. 关于extra加强延迟加载

    一对多和多对多关联的查询策略 lazy属性的另一个属性extra 加强延迟加载 表明采用增强延迟加载策略:在<set>元素配置lazy属性为"extra".增强延迟加载 ...

  4. .NET 4.5 WPF Ribbon

    文/嶽永鹏 Visual Studio 2012  DO.NET 4.5 Ribbon 界面编程. 代码 =============================================== ...

  5. iOS开发UI篇—UIScrollView控件介绍

    iOS开发UI篇—UIScrollView控件介绍 一.知识点简单介绍 1.UIScrollView控件是什么? (1)移动设备的屏幕⼤大⼩小是极其有限的,因此直接展⽰示在⽤用户眼前的内容也相当有限 ...

  6. iOS开发UI篇—APP主流UI框架结构

    iOS开发UI篇—APP主流UI框架结构 一.简单示例 说明:使用APP主流UI框架结构完成简单的界面搭建 搭建页面效果:                                二.搭建过程和 ...

  7. terminator终端工具

    terminator是个很好的终端程序,在Ubuntu Linux下安装如下: sudo apt-get install terminator 可在同一屏打开多个窗口:

  8. MicroERP主要业务流程示意图

    库存(进销存)管理 财务管理 固定资产管理 生产管理

  9. CodeForces 688D-Remainders Game

    题意: 已知n, k与n个整数(c1,c2,...,cn),问你是否存在一个数x,使得它能被n个整数且k整除. 分析: 可以先将n个整数的最小公倍数lcm计算出来,再判断它是否能被k整除. 代码如下: ...

  10. linux kernel tainted

    日志中会有一些信息: dmesg | grep -i tainted 具体代码可以通过proc看到: cat /proc/sys/kernel/tainted 数字的意义: tainted: Non- ...