package leetcode;

/**
 * https://leetcode.com/problems/integer-replacement/
 */
public class Problem397 {
    public int integerReplacement(int n) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem397 prob = new Problem397();
        System.out.println(prob.integerReplacement(8)); // 3
        System.out.println(prob.integerReplacement(7)); // 4
    }
}

@@ -155,16 +155,117 @@
     
-// TODO%0A
+return (int) longReplacement(n);%0A    %7D%0A%0A    private long longReplacement(long n) %7B%0A        if (n == 1) %7B%0A    
     
@@ -282,56 +282,40 @@
  0;%0A
+    
     %7D%0A
-%0A
+ 
     
-public static void main(String%5B%5D args
+   if (n %25 2 == 0
 ) %7B%0A
@@ -326,165 +326,177 @@
     
+ 
-Problem397 prob = new Problem397();%0A        System.out.println(prob.integerReplacement(8)); // 3%0A        System.out.println(prob.integerReplacement(7)); // 4
+   return longReplacement(n / 2) + 1;%0A        %7D%0A        long a = longReplacement(n - 1) + 1;%0A        long b = longReplacement(n + 1) + 1;%0A        return Math.min(a, b);
 %0A   

Solve problem 397