package leetcode;

/**
 * https://leetcode.com/problems/maximum-gap/
 */
public class Problem164 {
    public int maximumGap(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem164 prob = new Problem164();
        System.out.println(prob.maximumGap(new int[]{3, 6, 9, 1})); // 3
        System.out.println(prob.maximumGap(new int[]{10})); // 0
    }
}

package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/maximum-gap/
 */
public class Problem164 {
    public int maximumGap(int[] nums) {
        if (nums.length < 2) {
            return 0;
        }
        Arrays.sort(nums);
        int answer = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            int diff = Math.abs(nums[i] - nums[i + 1]);
            answer = Math.max(answer, diff);
        }
        return answer;
    }
}

Solve problem 164