Maximum Gap

Problem Id: 164 Difficulty: Hard


Intuition

Solution


class Solution:
    def maximumGap(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums) < 2:
            return 0

        nums = sorted(nums)
        max_diff = 0
        for i in range(len(nums)-1):
            if nums[i+1] - nums[i] > max_diff:
                max_diff = nums[i+1] - nums[i]
        return max_diff