classSolution{public:intmySqrt(intx){unsignedl=1;unsignedr=x+1u;while(l<r){constunsignedm=(l+r)/2;if(m>x/m)r=m;elsel=m+1;}// l := the minimum number s.t. l * l > xreturnl-1;}};
1 2 3 4 5 6 7 8 91011121314151617
classSolution{publicintmySqrt(longx){longl=1;longr=x+1;while(l<r){finallongm=(l+r)/2;if(m>x/m)r=m;elsel=m+1;}// l := the minimum number s.t. l * l > xreturn(int)l-1;}}