Java实现 LeetCode 367 有效的完全平方数
2024-09-04 05:12:06
367. 有效的完全平方数
给定一个正整数 num,编写一个函数,如果 num 是一个完全平方数,则返回 True,否则返回 False。
说明:不要使用任何内置的库函数,如 sqrt。
示例 1:
输入:16
输出:True
示例 2:
输入:14
输出:False
PS:
牛顿迭代法
class Solution {
public boolean isPerfectSquare(int num) {
if (num < 2) return true;
long x = num;
while (x * x > num) {
x = (x + num / x) / 2;
if (x * x == num) {
return true;
}
}
return false;
}
}
最新文章
- [spring源码学习]十、IOC源码-conversionService
- C和指针 第九章 习题
- 在centos6.7用yum安装redis解决办法
- Oracle优化总结
- jQuery知识点总结(第四天)
- POJ3764 The xor-longest Path(Trie树)
- Using QEMU for Embedded Systems Development
- MySQL之查询优化方式(笔记)
- 调用android方法,出现版本太低解决方法
- JSON取值(key是中文或者数字)方式详解
- gitlab服务器搭建教程
- IntelliJ IDEA编辑器光标定位错误的问题!
- ASP.NET Web API相关
- 导入到eclipse里的工程挺大的,然后就一直报: An internal error occurred during: ";Building workspace";. GC overhead limit exceeded 这个错误。
- mysql8.0发布新特性
- PHP文件上传与下载
- No.02——第一次使用Android Studio,并创建出Hello World
- python salt 实现windows账户自动化
- 锐捷 rg-S2026f 学习笔记
- 实例-PHP_SELF、 SCRIPT_NAME、 REQUEST_URI区别-获取前台公用文-dirname-PHP的";魔术常量";-str_replace