Maximum Gap
Given an integer array nums, return the maximum difference between two successive elements in its sorted form.
If nums contains fewer than two elements, return 0.
Your solution must run in O(n) time and use O(n) extra space.
Example 1
Input
nums = [3,6,9,1]Output
3After sorting, the array is [1, 3, 6, 9], and the maximum successive difference is 3.
Example 2
Input
nums = [10]Output
0There is only one element, so there are no successive elements to compare.
Constraints
- 1 <= nums.length <= 10^5
- 0 <= nums[i] <= 10^9