Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. int Solution::sqrt(int A) {
  2. if (A == 1) return 1;
  3. long long from = 1;
  4. long long to = A;
  5. long long res = 0;
  6. while(from <= to) {
  7. long long mid = from + (to - from) / 2;
  8. if (mid * mid == A) return mid;
  9. if (mid * mid < A) {res = mid; from = mid + 1;}
  10. else to = mid - 1;
  11. }
  12.  
  13. return res;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement