LeetCode_367. Valid Perfect Square
367. Valid Perfect Square
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
Output: true
Example 2:
Input: 14
Output: false
package leetcode.easy;
public class ValidPerfectSquare {
public boolean isPerfectSquare(int num) {
for (long i = 1; i <= num; i++) {
if (i * i == num) {
return true;
} else if (i * i > num) {
break;
} else {
continue;
}
}
return false;
}
@org.junit.Test
public void test() {
System.out.println(isPerfectSquare(16));
System.out.println(isPerfectSquare(14));
}
}
LeetCode_367. Valid Perfect Square的更多相关文章
- 367. Valid Perfect Square
原题: 367. Valid Perfect Square 读题: 求一个整数是否为完全平方数,如1,4,9,16,……就是完全平方数,这题主要是运算效率问题 求解方法1:812ms class So ...
- Leetcode之二分法专题-367. 有效的完全平方数(Valid Perfect Square)
Leetcode之二分法专题-367. 有效的完全平方数(Valid Perfect Square) 给定一个正整数 num,编写一个函数,如果 num 是一个完全平方数,则返回 True,否则返回 ...
- [LeetCode] 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
Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...
- 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
题目描述: Given a positive integer num, write a function which returns True if num is a perfect square e ...
- [Swift]LeetCode367. 有效的完全平方数 | 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验证完全平方数
Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...
- 367. Valid Perfect Square判断是不是完全平方数
[抄题]: Given a positive integer num, write a function which returns True if num is a perfect square e ...
随机推荐
- indexOf()、lastIndexOf()、startsWith()等方法应用
- Set的常用实现类HashSet和TreeSet
Set HashSet public static void main(String[] args) { //不可以重复 并且是无序的 //自然排序 从A-Z //eqauls从Object继 ...
- BZOJ 2333: [SCOI2011]棘手的操作
题目描述 真的是个很棘手的操作.. 注意每删除一个点,就需要clear一次. #include<complex> #include<cstdio> using namespac ...
- UOJ#221. 【NOI2016】循环之美 数论,杜教筛
原文链接www.cnblogs.com/zhouzhendong/p/UOJ221.html 题解 首先把题目转化为求 \[\sum_{x=1}^n \sum_{y=1}^m [\gcd(x,y) = ...
- ModuleNotFoundError: No module named 'cv2'
pip3 install opencv-python
- FCS省选模拟赛 Day5
传送门 Solution Code #include<bits/stdc++.h> #define ll long long #define max(a,b) ((a)>(b)?( ...
- kubernetes 1.14安装部署helm插件
简单介绍: Helm其实就是一个基于Kubernetes的程序包(资源包)管理器,它将一个应用的相关资源组织成为Charts,并通过Charts管理程序包.再简单点说,可以当做RHEL/CentOS系 ...
- ICEM-八分之一球体
原视频下载链接:https://yunpan.cn/c6seunjgbwRhJ 访问密码 c780
- 数据结构Java版之深度优先-图(十二)
这里用深度优先遍历存在矩阵里面的图. 深度优先利用的是栈的FIFO特性.为此遍历到底后,可以找到最相邻的节点继续遍历.实现深度优先,还需要在节点加上一个访问标识,来确定该节点是否已经被访问过了. 源码 ...
- 初识kubernetes
Kubernetes最初源于谷歌内部的Borg,提供了面向应用的容器集群部署和管理系统.Kubernetes 的目标旨在消除编排物理/虚拟计算,网络和存储基础设施的负担,并使应用程序运营商和开发人员完 ...