leetcode-164. 最大间距

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public int maximumGap(int[] nums) {
Arrays.sort(nums);
int n = nums.length;
if(n < 2){
return 0;
}
int max = Integer.MIN_VALUE;
for(int i = 1; i < n; i++){
max = Math.max(max, nums[i] - nums[i-1]);
}
return max;
}
}