title: Finding the square root of a number by using binary search
body: <p>I tried using binary search to find the square root of an integer, but some how I couldn't pass a few test cases.</p>
  
  <p>I was able to pass mySqrt(4) = 2, but I wasn't able to pass mySqrt(2147395599) </p>
  
  <p>Any ideas on where I messed up?</p>
  
  <pre><code>public static int mySqrt(int x) {
          int left = 0;
          int right = x;
  
          if(x &lt; 2){
              return x;
          }
          while(left &lt; right){
              int mid = left + ((right - left) / 2);
  
              if(mid * mid == x){
                  return mid;
  
              }
              else if(mid * mid &lt; x){
                  left = mid + 1;
              }
              else{
                  right = mid; 
              }
          }
          return left - 1;
      }
  </code></pre>