Clean Python Solution


  • 0
    T
    class Solution(object):
        def findMissingRanges(self, nums, lower, upper):
            nums.insert(0,lower-1)
            nums.append(upper+1)
            i,j = 0,1
            res = []
            while j < len(nums):
                if nums[j] - nums[i] == 2:
                    res.append(str(nums[i]+1))
                elif nums[j] - nums[i] > 2:
                    res.append(str(nums[i]+1) + '->' +str(nums[j]-1))
                i += 1
                j += 1
            return res
    

Log in to reply
 

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