Simple and clear python solution


  • 1
    def findMissingRanges(self, nums, lower, upper):
        """
        :type nums: List[int]
        :type lower: int
        :type upper: int
        :rtype: List[str]
        """
        result=[]
        nums.insert(0,lower-1)
        nums.append(upper+1)
        for i in range(0,len(nums)-1):
            a=nums[i]
            b=nums[i+1]
            if a==b or a+1==b:
                pass
            elif a+2==b:
                result.append(str(a+1))
            else:
                result.append(str(a+1) + '->' + str(b-1))
        return result

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.