package leetcode;

/**
 * https://leetcode.com/problems/sqrtx/
 */
public class Problem69 {
    public int mySqrt(int x) {
        // TODO:
        return 0;
    }

    public static void main(String[] args) {
        Problem69 prob = new Problem69();
    }
}

@@ -131,123 +131,602 @@
  // 
-TODO:%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B
+using Newton's method%0A        // https://www.youtube.com/watch?v=2158QbsunA8%0A        double sqrt = sqrt(x, x);%0A        while (true) %7B%0A            double tmp = sqrt;%0A            sqrt = sqrt(sqrt, x);%0A            if (Double.isNaN(sqrt) %7C%7C tmp - sqrt %3C 1) %7B%0A                break;%0A            %7D%0A        %7D%0A        return (int) sqrt;%0A    %7D%0A%0A    private double fx(double x, double y) %7B%0A        return (x * x) - y;
 %0A    
+%7D%0A%0A
     
-Problem69 prob = new Problem69(
+private double dfx(double x) %7B%0A        // the derivative of fx%0A        return 2 * x;%0A    %7D%0A%0A    private double sqrt(double x, double y) %7B%0A        return x - (fx(x, y) / dfx(x)
 );%0A 

Solve problem 69