Clean short python code


  • 1
    class Solution(object):
        def findMissingRanges(self, nums, lower, upper):
            gen = (lambda i, j: ['%s->%s' % (i + 1, j - 1), str(i + 1)][i == j - 2])
    
            nums = [lower - 1] + nums + [upper + 1]
            return [
                gen(nums[i - 1], nums[i])
                for i in xrange(1, len(nums)) if nums[i] - nums[i - 1] > 1
            ]

Log in to reply
 

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