求平方根
求平方根
http://www.nowcoder.com/questionTerminal/09fbfb16140b40499951f55113f2166c
import java.util.*; public class Solution { /** * * @param x int整型 * @return int整型 */ public static int sqrt (int x) { // write code here if(x == 0 || x == 1){ return x; } long r = x; long result = r * r; while(x < result){ r = (r+x/r)/2; result = r * r; } return (int)r; } }