package leetcode;

/**
 * https://leetcode.com/problems/broken-calculator/
 */
public class Problem991 {
    public int brokenCalc(int X, int Y) {
        if (X == Y) {
            return 0;
        }
        int a = Integer.MAX_VALUE;
        int b = Integer.MAX_VALUE;
        if (X < Y) {
            a = brokenCalc(X * 2, Y) + 1;
        }
        if (X > Y) {
            b = brokenCalc(X - 1, Y) + 1;
        }
        int min = Math.min(a, b);
        return min;
    }

    public static void main(String[] args) {
        Problem991 prob = new Problem991();
//        System.out.println(prob.brokenCalc(2, 3)); // 2
//        System.out.println(prob.brokenCalc(5, 8)); // 2
        System.out.println(prob.brokenCalc(3, 10)); // 3
//        System.out.println(prob.brokenCalc(1024, 1)); // 1023
    }
}

@@ -153,185 +153,76 @@
    i
-f (X == Y) %7B%0A            return 0;%0A        %7D%0A        int a = Integer.MAX_VALUE;%0A        int b = Integer.MAX_VALUE;%0A        if (X %3C Y) %7B%0A            a = brokenCalc(X * 2, Y) + 1;
+nt answer = 0;%0A        while (Y %3E X) %7B%0A            if (Y %25 2 == 1) %7B
 %0A   
@@ -226,26 +226,24 @@
         
-%7D%0A
         
 if (X %3E 
@@ -238,20 +238,12 @@
     
-if (X %3E Y) %7B
+Y++;
 %0A   
@@ -255,37 +255,16 @@
     
-b = brokenCalc(X - 1, Y) + 1;
+%7D else %7B
 %0A   
@@ -272,18 +272,16 @@
     
-%7D%0A
         
 int 
@@ -280,386 +280,92 @@
     
-int min = Math.min(a, b);%0A        return min;%0A
+Y /= 2;%0A        
     %7D%0A
-%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem991 prob = new Problem991();%0A//        System.out.println(prob.brokenCalc(2, 3)); // 2%0A//        System.out.println(prob.brokenCalc(5, 8)); // 2%0A        System.out.println(prob.brokenCalc(3, 10)); // 3%0A//        System.out.println(prob.brokenCalc(1024, 1)); // 1023
+        answer++;%0A        %7D%0A        return answer + X - Y;
 %0A   

Solve problem 991