package com.fishercoder.solutions;

/**
 * Implement int sqrt(int x).

 Compute and return the square root of x.

 * Created by fishercoder on 1/25/17.
 */
public class _69 {
    public int mySqrt(int x) {
        long i = 0;
        long j = x / 2 + 1;
        while (i <= j) {
            long mid = (i + j) / 2;
            long result = mid * mid;
            if (result == (long) x) {
                return (int) mid;
            } else if (result > x) {
                j = mid - 1;
            } else {
                i = mid + 1;
            }
        }
        return (int) j;
    }
}

@@ -33,16 +33,31 @@
 s;%0A%0A/**%0A
+ * 69. Sqrt(x)%0A
  * Imple
@@ -78,17 +78,18 @@
 int x).%0A
-%0A
+ *
  Compute
@@ -125,52 +125,14 @@
 f x.
-%0A%0A * Created by fishercoder on 1/25/17.
 %0A */%0A
+%0A
 publ
@@ -190,17 +190,20 @@
    long 
-i
+left
  = 0;%0A  
@@ -213,17 +213,21 @@
    long 
-j
+right
  = x / 2
@@ -251,14 +251,21 @@
 le (
-i %3C= j
+left %3C= right
 ) %7B%0A
@@ -291,14 +291,28 @@
 d = 
-(i + j
+left + (right - left
 ) / 
@@ -476,17 +476,21 @@
         
-j
+right
  = mid -
@@ -530,17 +530,20 @@
         
-i
+left
  = mid +
@@ -595,9 +595,13 @@
 nt) 
-j
+right
 ;%0A  

refactor 69