Simple 10-line Python Solution


  • 0
    M
        def findMissingRanges(self, nums, lower, upper):
            ret = []        
            nums = [lower-1] + nums + [upper+1]
            for i in xrange(len(nums)-1):
                if nums[i+1] - nums[i] > 1:
                    first, second = nums[i] + 1, nums[i+1] - 1
                    if first != second:
                        ret.append('->'.join(map(str, [first, second])))
                    else:
                        ret.append(str(first))
            return ret
    

Log in to reply
 

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