标签:style blog color io java ar for 2014 div
Implement int sqrt(int x)
.
Compute and return the square root of x.
public class Solution { public int sqrt(int x) { if (x == 0) { return 0; } if (x < 4) { return 1; } int n=15; long result=0; long maxNum; for(;n>=0;n--){ maxNum=1<<n; if((result+maxNum)*(result+maxNum)<=x){ result+=maxNum; } } return (int)result; } }
标签:style blog color io java ar for 2014 div
原文地址:http://blog.csdn.net/jiewuyou/article/details/39290299