leetcode 367 Valid Perfect Square
题目连接
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相关推荐
- [leetcode] 367. Valid Perfect Square
Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...
- leetcode 367. Valid Perfect Square
二分. bool isPerfectSquare(int num) {if (num == 0 || num == 1)return true;int start = 0;int end = num; ...
- 367. Valid Perfect Square
题目: Given a positive integer num, write a function which returns True if num is a perfect square els ...
- C#LeetCode刷题之#367-有效的完全平方数(Valid Perfect Square)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3869 访问. 给定一个正整数 num,编写一个函数,如果 num ...
- LeetCode Valid Perfect Square(是否是平方数)
题意:给出一正整数,不用 sqrt函数,判断该数是否是平方数 思路: 第一种,连续奇数和为平方数 代码如下: public class Solution {public boolean isPerfe ...
- Leetcode 279. Perfect Square
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...
- 【To Do! 重点 正则表达式】LeetCode 65. Valid Number
LeetCode 65. Valid Number 本博客转载自:[1]http://www.cnblogs.com/yuzhangcmu/p/4060348.html [2]https://blog ...
- 【回文串14】LeetCode 680. Valid Palindrome II
LeetCode 680. Valid Palindrome II Solution1:我的答案 复杂度是O(n)O(n)O(n),不算好啊.. 注意:对于c++中string对象常用的insert( ...
- 【回文串3】LeetCode 125. Valid Palindrome
LeetCode 125. Valid Palindrome Solution1:我的答案 复杂度为O(n)O(n)O(n),写法不是很简练啊. class Solution { public:boo ...
- LeetCode 36. Valid Sudoku
LeetCode 36. Valid Sudoku Solution1:我的答案,比较笨.但是清晰易懂好上手啊~~~ class Solution { public:bool isValidSudok ...
最新文章
- 基于ip地址的客户识别原理_使用 LVS 实现负载均衡原理及安装配置
- opencv检测矩形
- matlab 如何定义符号数组
- 十分经典的批处理教程
- TensorFlow与主流深度学习框架对比
- hdu 5023 poj 2777(线段染色)2014 ACM/ICPC Asia Regional 广州 Online
- 容器学习 之 容器访问外部网络(十四)
- java 菜单快捷键_Java 菜单快捷键
- uva 11584——Partitioning by Palindromes
- jQuery左右循环滚动图片特效
- boost 容器tuple 信号signal2测试
- edius隐藏快捷键_EDIUS素材隐藏快捷键是什么啊?
- AODV路由协议详解
- 运行iphone模拟器
- win7下安装python库的若干问题
- 基于LSTM的股票预测模型_python实现_超详细
- 第996号互联网世界终结了
- 串口接收不定长数据的几种方式
- 【Python】批量下载新浪微博某用户的头像相册
- 自由枪骑兵-Freelancer
热门文章
- saltstack 自动化运维神器(四)salt-ssh
- ubuntu如何解压.tar.gz
- Android -- Sqlite事务
- StringUtils 方法介绍(转载)
- Volume Shadow Copy Service(VSS)如何工作
- 执行查看linux端口命令 9083 端口发现被占用 Hive安装过程遇到的问题
- 趣图:SQL 版的喝椰汁,没想到吧
- “技术天才”李一男已出狱:曾被视为华为接班人!华中科大少年班,27岁华为副总裁,曾任百度CTO...
- 让能力变现,才是硬道理
- iif能用到mysql中吗_数据库 iif