码迷,mamicode.com
首页 > 其他好文 > 详细

Sqrt(x)

时间:2014-06-04 19:54:17      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

Implement int sqrt(int x).

Compute and return the square root of x.

bubuko.com,布布扣
class Solution {
public:
    int sqrt(int x) 
    {
        int i=0;
        int step=1;
        
        while(step>0)
        {
            while((i+step)<=x/(i+step)) 
            {
                i=i+step;
                step=(step<<1);
            }
            step=(step>>1);
        }
        return i;
    }
}; 
bubuko.com,布布扣

Sqrt(x),布布扣,bubuko.com

Sqrt(x)

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/erictanghu/p/3759473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!