# Hard-题目16：164. Maximum Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.

Try to solve it in linear time/space.

Return 0 if the array contains less than 2 elements.

You may assume all elements in the array are non-negative integers and fit in the 32-bit signed integer range.

public class Solution {
public int maximumGap(int[] nums) {
if(nums.length<2)
return 0;
Arrays.sort(nums);
int maxgap = Integer.MIN_VALUE;
for(int i = 1;i<nums.length;i++) {
if(nums[i]-nums[i-1]>maxgap)
maxgap=nums[i]-nums[i-1];
}
return maxgap;
}
}

4ms,beats 92.15%,众数6ms,27.29%
Cmershen的碎碎念：

• 本文已收录于以下专栏：

## leetcode 164. Maximum Gap 最大间隔 + 一个很好的桶排序示范

Given an unsorted array, find the maximum difference between the successive elements in its sorted f...

## leetcode164~Maximum Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted f...

## 164. Maximum Gap【H】【80】【桶排序】【VIP】

Given an unsorted array, find the maximum difference between the successive elements in its sorted f...
• sscssz
• 2016年05月13日 21:55
• 398

## [LeetCode164] Maximum Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted f...
• sbitswc
• 2015年08月15日 13:33
• 1078

## LeetCode #164 Maximum Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted f...

## 164. Maximum Gap

Given an array nums, there is a sliding window of size k which is moving from the very left of the a...

## [LeetCode]problem 164. Maximum Gap

TAG桶排序浮点数不精确link方法一眼看过去完全不知道该怎么做。看了题解觉得很高端的样子，再后来多看了下，发现本质其实就是一个线性时间排序的问题！线性时间排序，有计数排序、桶排序、基数排序。计数排序...

## [164]Maximum Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted f...

举报原因： 您举报文章：Hard-题目16：164. Maximum Gap 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)