website/content.en/ChapterFour/0300~0399/0367.Valid-Perfect-Square.md
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
Given a positive integer num, write a function that returns True if num is a perfect square, otherwise returns False.
Note: Do not use any built-in library function such as sqrt.
package leetcode
func isPerfectSquare(num int) bool {
low, high := 1, num
for low <= high {
mid := low + (high-low)>>1
if mid*mid == num {
return true
} else if mid*mid < num {
low = mid + 1
} else {
high = mid - 1
}
}
return false
}