Files
2020-08-09 00:39:24 +08:00

34 lines
948 B
Markdown
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [367. Valid Perfect Square](https://leetcode.com/problems/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
## 题目大意
给定一个正整数 num编写一个函数如果 num 是一个完全平方数,则返回 True否则返回 False。
说明不要使用任何内置的库函数 sqrt。
## 解题思路
- 给出一个数,要求判断这个数是不是完全平方数。
- 可以用二分搜索来解答这道题。判断完全平方数,根据它的定义来,是否能被开根号,即找到一个数的平方是否可以等于待判断的数字。从 [1, n] 区间内进行二分,若能找到则返回 true找不到就返回 false 。