solution.cpp 414 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Solution
{
public:
    int maximumGap(vector<int> &nums)
    {
        if (nums.size() < 2)
            return 0;
        sort(nums.begin(), nums.end());
        int max_difference = 0;
        for (int i = 0; i < nums.size() - 1; i++)
        {
            if (nums[i + 1] - nums[i] > max_difference)
                max_difference = nums[i + 1] - nums[i];
        }
        return max_difference;
    }
};