# [164\. 最大间距[困难]](https://leetcode-cn.com/problems/maximum-gap/)
![](https://box.kancloud.cn/6e3bce52cfa2bcb5aede798b3c1d712e_603x420.png)
~~~
func maximumGap(nums []int) int {
if len(nums) < 2 {
return 0
}
ints := sor(nums)
max := ints[1] - ints[0]
for i:=1;i<len(ints);i++{
ds := ints[i] - ints[i-1]
if max < ds {
max = ds
}
}
return max
}
// 排序
func sor(nums []int) []int {
for i:=0;i<len(nums);i++{
min := nums[i]
for j:=len(nums) - 1;j>i;j--{
if min > nums[j] {
min,nums[j] = nums[j],min
}
}
nums[i] = min
}
return nums
}
~~~