package leetcode;

/**
 * https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer/
 */
public class Problem1432 {
    public int maxDiff(int num) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1432 prob = new Problem1432();
        System.out.println(prob.maxDiff(555)); // 888
        System.out.println(prob.maxDiff(9)); // 8
        System.out.println(prob.maxDiff(123456)); // 820000
        System.out.println(prob.maxDiff(10000)); // 80000
        System.out.println(prob.maxDiff(9288)); // 8700
    }
}

@@ -179,32 +179,1171 @@
     
-// TODO%0A        return 0
+String s = Integer.toString(num);%0A        int i = 0;%0A        while (i %3C s.length() && s.charAt(i) == '9') %7B%0A            i++;%0A        %7D%0A        StringBuilder max = new StringBuilder();%0A        if (i == s.length()) %7B%0A            i = 0;%0A        %7D%0A        for (int j = 0; j %3C s.length(); j++) %7B%0A            if (s.charAt(i) == s.charAt(j)) %7B%0A                max.append(%229%22);%0A            %7D else %7B%0A                max.append(s.charAt(j));%0A            %7D%0A        %7D%0A        StringBuilder min = new StringBuilder();%0A        i = 0;%0A        boolean zero = false;%0A        if (s.charAt(i) == '1') %7B%0A            while (i %3C s.length() && s.charAt(i) == '1') %7B%0A                i++;%0A            %7D%0A            if (i == s.length()) %7B%0A                i = 0;%0A            %7D else %7B%0A                zero = true;%0A            %7D%0A        %7D%0A%0A        for (int j = 0; j %3C s.length(); j++) %7B%0A            if (s.charAt(i) == s.charAt(j)) %7B%0A                min.append(zero ? %220%22 : %221%22);%0A            %7D else %7B%0A                min.append(s.charAt(j));%0A            %7D%0A        %7D%0A        System.out.println(max + %22 %22 + min);%0A        return Integer.parseInt(max.toString()) - Integer.parseInt(min.toString())
 ;%0A  
@@ -1434,24 +1434,26 @@
 blem1432();%0A
+//
         Syst
@@ -1494,16 +1494,18 @@
  // 888%0A
+//
         
@@ -1546,16 +1546,18 @@
 ); // 8%0A
+//
         
@@ -1604,24 +1604,26 @@
 ; // 820000%0A
+//
         Syst
@@ -1668,16 +1668,18 @@
 / 80000%0A
+//
         
@@ -1726,16 +1726,362 @@
 // 8700%0A
+//        System.out.println(prob.maxDiff(9289)); // 8708%0A//        System.out.println(prob.maxDiff(1111)); // 8888%0A//        System.out.println(prob.maxDiff(9999)); // 8888%0A//        System.out.println(prob.maxDiff(1000)); // 8000%0A//        System.out.println(prob.maxDiff(3)); // 8%0A        System.out.println(prob.maxDiff(1101057)); // 8808050%0A
     %7D%0A%7D%0A

Update problem 1432