164. Maximum Gap Hard
1/**
2 * [164] Maximum Gap
3 *
4 * Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0.
5 * You must write an algorithm that runs in linear time and uses linear extra space.
6 *
7 * Example 1:
8 *
9 * Input: nums = [3,6,9,1]
10 * Output: 3
11 * Explanation: The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3.
12 *
13 * Example 2:
14 *
15 * Input: nums = [10]
16 * Output: 0
17 * Explanation: The array contains less than 2 elements, therefore return 0.
18 *
19 *
20 * Constraints:
21 *
22 * 1 <= nums.length <= 10^5
23 * 0 <= nums[i] <= 10^9
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/maximum-gap/
29// discuss: https://leetcode.com/problems/maximum-gap/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn maximum_gap(nums: Vec<i32>) -> i32 {
35 0
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_164() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.