367. Valid Perfect Square

Easy

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的更多相关文章

  1. 367. Valid Perfect Square

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

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

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

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

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

  4. Leetcode 367. Valid Perfect Square

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

  5. 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 e ...

  7. [Swift]LeetCode367. 有效的完全平方数 | Valid Perfect Square

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

  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. 367. Valid Perfect Square判断是不是完全平方数

    [抄题]: Given a positive integer num, write a function which returns True if num is a perfect square e ...

随机推荐

  1. #define的一个小技巧

    /* atof example: sine calculator */ #include <stdio.h> /* printf, fgets */ #include <stdlib ...

  2. Continuous Subarray Sum II

    Description Given an circular integer array (the next element of the last element is the first eleme ...

  3. [NgRx] NgRx Data Fetching Solution - How to Load Data Only If Needed

    We have a reoslver, which everytime we want visit '/courses' route, it will be triggered, then api w ...

  4. Storm 安装时 部分supervisor启动成功,并不在web ui上显示

    今天帮公司搭建集群时,发现启动了三个Supervisor 发现只有一个显示在Web UI 上. 于是我就简单地检查了下另外两台没有启动的 storm supervisor的日志, 发现没有报出什么异常 ...

  5. H3CNE学习6 静态路由

    一.相应命令 1.查看路由表 2.直连路由 3.静态路由配置 4.路由器转发数据包 二.静态路由2 1.路由优先级 管理距离即优先级,值越小就越优先 2.路由度量 如果上下都是使用的相同的路由协议那么 ...

  6. The Last Goodbye 电影《霍比特人3:五军之战》插曲

    https://music.163.com/#/song?id=29755223 I saw the light fade from the sky我看到天空褪去色彩On the wind I hea ...

  7. AutoCAD .NET二次开发(一)

    其他话不多说,直接进入主题,既然是二次开发,当然是用CAD平台已经封装好了很多类,我们需要熟悉和使用它们.常用的AutoCAD .NET API的四个主要DLL文件是: 名称 作用 备注 AcDbMg ...

  8. segfault at 0 ip sp error 14

    error 14从未见过.谁能帮我解答什么情况才会出现这个,而且怎么定位崩溃函数地址? 备忘: segfault at 引起故障的地址ip 指令的内存地址sp 堆栈指针地址, 及栈顶指针err is ...

  9. 部署Django到云服务器(centos+nginx+mysql+uwsgi+python3)【操作篇(1)】

    开篇 笛卡尔说:"你不能教会一个人任何东西,你只能帮助他发现他自己内心本来就有的东西!" jacky能教你的,只能是经验和建议,要逆袭还得通过自己对数据的不断领悟,数据领域的技能都 ...

  10. Codeforces 876E National Property ——(2-SAT)

    在这题上不是标准的“a或b”这样的语句,因此需要进行一些转化来进行建边.同时在这题上点数较多,用lrj大白书上的做法会T,因此采用求强连通分量的方法来求解(对一个点,如果其拓扑序大于其为真的那个点,则 ...