6 Line Python


  • 0
    class Solution(object):
        def findMissingRanges(self, nums, lower, upper):
            nums, ans, pre = [lower - 1] + nums + [upper + 1], [], lower - 1
            for i in xrange(1, len(nums)):
                if nums[i] != nums[i - 1] and nums[i] != pre + 1:
                    ans.append( str(pre + 1) if pre + 1 == nums[i] - 1 else str(pre + 1) + '->' + str(nums[i] - 1) )
                pre = nums[i]
            return ans
    

Log in to reply
 

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