题目连接

https://leetcode.com/problems/valid-perfect-square/

Valid Perfect Square

Description

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

Note: Do not use any built-in library function such as sqrt.

Example 1:

Input: 16
Returns: True

Example 2:

Input: 14
Returns: False

二分

class Solution {
public:bool isPerfectSquare(int num) {int lb = 1, ub = 92682;while(lb <= ub) {int m = (lb + ub) >> 1;long long v = (long long)m * m;if(v == num) return true;if(v > num) ub = m - 1;else lb = m + 1;}return false;}
};

转载于:https://www.cnblogs.com/GadyPu/p/5631274.html

leetcode 367 Valid Perfect Square相关推荐

  1. [leetcode] 367. 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

    二分. bool isPerfectSquare(int num) {if (num == 0 || num == 1)return true;int start = 0;int end = num; ...

  3. 367. Valid Perfect Square

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

  4. C#LeetCode刷题之#367-有效的完全平方数(Valid Perfect Square)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3869 访问. 给定一个正整数 num,编写一个函数,如果 num ...

  5. LeetCode Valid Perfect Square(是否是平方数)

    题意:给出一正整数,不用 sqrt函数,判断该数是否是平方数 思路: 第一种,连续奇数和为平方数 代码如下: public class Solution {public boolean isPerfe ...

  6. Leetcode 279. Perfect Square

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  7. 【To Do! 重点 正则表达式】LeetCode 65. Valid Number

    LeetCode 65. Valid Number 本博客转载自:[1]http://www.cnblogs.com/yuzhangcmu/p/4060348.html [2]https://blog ...

  8. 【回文串14】LeetCode 680. Valid Palindrome II

    LeetCode 680. Valid Palindrome II Solution1:我的答案 复杂度是O(n)O(n)O(n),不算好啊.. 注意:对于c++中string对象常用的insert( ...

  9. 【回文串3】LeetCode 125. Valid Palindrome

    LeetCode 125. Valid Palindrome Solution1:我的答案 复杂度为O(n)O(n)O(n),写法不是很简练啊. class Solution { public:boo ...

  10. LeetCode 36. Valid Sudoku

    LeetCode 36. Valid Sudoku Solution1:我的答案,比较笨.但是清晰易懂好上手啊~~~ class Solution { public:bool isValidSudok ...

最新文章

  1. 基于ip地址的客户识别原理_使用 LVS 实现负载均衡原理及安装配置
  2. opencv检测矩形
  3. matlab 如何定义符号数组
  4. 十分经典的批处理教程
  5. TensorFlow与主流深度学习框架对比
  6. hdu 5023 poj 2777(线段染色)2014 ACM/ICPC Asia Regional 广州 Online
  7. 容器学习 之 容器访问外部网络(十四)
  8. java 菜单快捷键_Java 菜单快捷键
  9. uva 11584——Partitioning by Palindromes
  10. jQuery左右循环滚动图片特效
  11. boost 容器tuple 信号signal2测试
  12. edius隐藏快捷键_EDIUS素材隐藏快捷键是什么啊?
  13. AODV路由协议详解
  14. 运行iphone模拟器
  15. win7下安装python库的若干问题
  16. 基于LSTM的股票预测模型_python实现_超详细
  17. 第996号互联网世界终结了
  18. 串口接收不定长数据的几种方式
  19. 【Python】批量下载新浪微博某用户的头像相册
  20. 自由枪骑兵-Freelancer

热门文章

  1. saltstack 自动化运维神器(四)salt-ssh
  2. ubuntu如何解压.tar.gz
  3. Android -- Sqlite事务
  4. StringUtils 方法介绍(转载)
  5. Volume Shadow Copy Service(VSS)如何工作
  6. 执行查看linux端口命令 9083 端口发现被占用 Hive安装过程遇到的问题
  7. 趣图:SQL 版的喝椰汁,没想到吧
  8. “技术天才”李一男已出狱:曾被视为华为接班人!华中科大少年班,27岁华为副总裁,曾任百度CTO...
  9. 让能力变现,才是硬道理
  10. iif能用到mysql中吗_数据库 iif