标签:span https ref eve none alt title ret tps
注意边界条件和判断条件
mid int存不下要用long long
class Solution { public: int mySqrt(int x) { int lower=1,upper=x; long long mid=lower+(upper-lower)/2; if(x==0) return 0; while(lower<mid) { if(mid*mid==x) return mid; if(mid*mid>x) { upper=mid; mid=lower+(upper-lower)/2; continue; } if(mid*mid<x) { lower=mid; mid=lower+(upper-lower)/2; continue; } } return mid; } };
标签:span https ref eve none alt title ret tps
原文地址:https://www.cnblogs.com/dzzy/p/12275653.html