Clean python one pass only


  • 0
    S

    class Solution(object):

    def findMissingRanges(self, nums, lower, upper):
        nums = [lower-1] + nums + [upper+1]
        pre = 0
        ret = []
        for i in range(1, len(nums)):
            if nums[i] == nums[i-1] + 2:
                ret.append(str(nums[i-1]+1))
            elif nums[i] > nums[i-1] + 2:
                ret.append(str(nums[i-1]+1)+"->"+str(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.