sqrtx

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

sqrtx.go 源码

package leetcode

// x的平方根

func sqrtx(x int) int {
	low, high := 1, x
	for low <= high {
		mid := low + (high-low)/2
		if x/mid < mid {
			high = mid - 1
		} else {
			low = mid + 1
		}
	}
	return high
}

你可能感兴趣的文章

first_and_last_in_sorted_array

first_bad_version

min_in_rotated_sorted_array

0  赞