[Go] Newton Iterative Sqrt Method


  • 0

    sum[1,x] <= 2*n < sum[1,x+1]

    func arrangeCoins(n int) int {
    	n *= 2
    	x := n
    	for !(x*(x+1) <= n && n < (x+1)*(x+2)) {
    		x = (x + n/(x+1)) / 2
    	}
    	return x
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.