Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- **/
- class Solution {
- public:
- int mySqrt(int x) {
- int l = 0, h = x;
- long long ans = 0;
- while(l <= h)
- {
- long long mid = l + ( h - l)/2;
- if(mid * mid >= x)ans = mid, h = mid-1;
- else l = mid+1;
- }
- if( ans * ans == (long long)x) return ans;
- return ans-1;
- }
- };
Add Comment
Please, Sign In to add comment