Guest User

Untitled

a guest
Nov 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. int mySqrt(int x) {
  2. int left = 0;
  3. int right = x/2+1;
  4. long long root = 0;
  5.  
  6. while(left<=right) {
  7. root = (left+right)/2;
  8. if(root*root < x) left = root+1;
  9. else if(root*root > x) right = root-1;
  10. else return root;
  11. }
  12.  
  13. return right;
  14. }
Add Comment
Please, Sign In to add comment