leetcode- Sqrt(x)
生活随笔
收集整理的這篇文章主要介紹了
leetcode- Sqrt(x)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
Implement?int sqrt(int x).
Compute and return the square root of?x.
class?Solution?{ public:int?mySqrt(int?x)?{if(x<=0)?return?0;int?begin=1,?end=x,?mid=0,?res=0,?tmp=0;while(begin<=end){mid=begin+(end-begin)/2;tmp=x/mid;if(tmp>mid){res=mid;begin?=?mid;}else?if(tmp<mid){end?=?end-1;}else?if(tmp==mid){res=mid;break;}}return?res;} };轉(zhuǎn)載于:https://my.oschina.net/u/2368952/blog/527542
總結(jié)
以上是生活随笔為你收集整理的leetcode- Sqrt(x)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: leetcode- Single Num
- 下一篇: Hdu1203