@@ -0,0 +1,1599 @@
+import java.util.Arrays;%0A%0Apublic class Solution %7B%0A%0A    public int maximumGap(int%5B%5D nums) %7B%0A        int n = nums.length;%0A        if(n %3C 2) return 0;%0A        int min = nums%5B0%5D, max = nums%5B0%5D;%0A        for (int i = 0; i %3C n; i++) %7B%0A            min = Math.min(min, nums%5Bi%5D);%0A            max = Math.max(max, nums%5Bi%5D);%0A        %7D%0A        if (min == max) return 0;%0A%0A        boolean%5B%5D empty = new boolean%5Bn+1%5D;%0A        Arrays.fill(empty, true);%0A        int%5B%5D  pmax = new int%5Bn+1%5D;%0A        int%5B%5D  pmin = new int%5Bn+1%5D;%0A%0A        for (int i = 0; i %3C n; i++) %7B%0A            int index = (int)(mul(nums%5Bi%5D-min, n+1)/(max - min));%0A            if(index %3E n)%7B%0A                index = n;%0A            %7D%0A            if (empty%5Bindex%5D)%7B%0A                empty%5Bindex%5D = false;%0A                pmax%5Bindex%5D = pmin%5Bindex%5D = nums%5Bi%5D;%0A            %7Delse%7B%0A                pmax%5Bindex%5D = Math.max(nums%5Bi%5D, pmax%5Bindex%5D);%0A                pmin%5Bindex%5D = Math.min(nums%5Bi%5D, pmin%5Bindex%5D);%0A            %7D%0A        %7D%0A%0A        int last = -1, answer = 0;%0A        for (int i = 0; i %3C= n; i++) %7B%0A            if(!empty%5Bi%5D) %7B%0A                if (last %3C 0) %7B%0A                    last = pmax%5Bi%5D;%0A                %7D else %7B%0A                    answer = Math.max(answer, pmin%5Bi%5D - last);%0A                    last = pmax%5Bi%5D;%0A                %7D%0A            %7D%0A        %7D%0A%0A        return answer;%0A    %7D%0A%0A    long mul(long x, long y)%7B%0A        return x * y;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D nums = %7B1, 2, 3, 4, 5, 6, 7, 8, 10%7D;%0A        Solution solution = new Solution();%0A        System.out.println(solution.maximumGap(nums));%0A    %7D%0A%7D%0A

complete problem 164