import math classSolution(object): defmaximumGap(self, nums): """ :type nums: List[int] :rtype: int """ ifnot nums or len(nums)<2:return0 self.radixSort(nums) maxgap = 0 for i in range(1,len(nums)): if nums[i]-nums[i-1]>maxgap: maxgap = nums[i]-nums[i-1] return maxgap defradixSort(self,nums,base=10): k = int(math.ceil(math.log(max(nums)+1,base))) for i in range(1,k+1): bucket = [[] for _ in range(base)] for num in nums: bucket[num//(base**(i-1))%base].append(num) del nums[:]#del nums[:]表示删除数组内的整数,nums变量还存在为[];del nums表示删除整个数组,nums变量不存在了 for each in bucket: nums.extend(each)