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. Idea导入maven项目

    1.idea中有项目的关闭项目  File>>close project  回到截图 下一步>下一步

  2. 转发标签forward

    当执行到<jsp:forward page="相对路径"></jsp:forward>后,会立即结束当前页面的显示,跳转到另一个页面(JSP.HTML.Se ...

  3. saltstack 在window下 发布 service 服务

    saltstack 发布 service 服务 如果是注册的服务发布:   salt -L '172.16.3.39' state.sls service.deploy 目录结构: /home/sal ...

  4. react 通过 xlink 方式引用 iconfont

    项目中采用 xlink 的方式引用 iconfont 文件,在正常的 html 文件中可以正常引用,但是在 react 下确不可以运行. 经过查找,发现需要更改如下 引入的属性默认为 xlink-hr ...

  5. [golang]A modern, fast and scalable websocket framework with elegant API written in Go

    A modern, fast and scalable websocket framework with elegant API written in Go http://bit.ly/neffos- ...

  6. manjaro (arch) 安装搜狗输入法

    本文通过MetaWeblog自动发布,原文及更新链接:https://extendswind.top/posts/technical/sogou_input_install_in_arch_manja ...

  7. mysql 统计查询出来的数目

    select count(*) as dd from users;

  8. 怎么把分化成元,并且保留两位小数,用vue来做

    <el-table-column prop="amount" label="申请提现金额" width="120" align=&qu ...

  9. SyntaxError: Non-ASCII character 'æ' in file csdn.py on line 7, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

    错误信息: SyntaxError: Non-ASCII character , but no encoding declared; see http://python.org/dev/peps/pe ...

  10. Java8中LocalDate的使用---项目中日期处理

    // 获取当前日期 LocalDate now = LocalDate.now(); // 设置日期 LocalDate now2 = LocalDate.of(2099, 2, 28); // 解析 ...