My Accepted 11 line python solution


  • 0
    P

    Add the high to the end of the list to avoid latter check.

        def findMissingRanges(self, nums, lower, upper):
    
        ret = []
        nums.append(upper+1)
        l = lower
        for i in range(len(nums)):
            if nums[i] >l:
                if nums[i] == l+1:
                    s = str(l)
                else:
                    s = str(l) + '->' + str(nums[i] -1)
                ret.append(s)
            l = nums[i] + 1
            
        return ret

Log in to reply
 

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