valid_perfect_square

  • 2022-12-14
  • 浏览 (484)

valid_perfect_square.go 源码

package leetcode

// 有效的完全平方数

func isPerfectSquare(num int) bool {
	low, high := 1, num
	for low <= high {
		mid := low + (high - low) / 2
		if mid * mid > num {
			high = mid - 1
		} else if mid * mid < num {
			low = mid + 1
		} else {
			return true
		}
	}
	return false
}

你可能感兴趣的文章

first_and_last_in_sorted_array

first_bad_version

min_in_rotated_sorted_array

0  赞