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: smallest number s.t. l * l > xreturnl-1;}};
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: smallest number s.t. l * l > xreturn(int)l-1;}}
classSolution:defmySqrt(self,x:int)->int:l=1r=x+1whilel<r:m=(l+r)//2ifm*m>x:r=melse:l=m+1# L: smallest number s.t. l * l > xreturnl-1