class Solution(object):
def findMissingRanges(self, nums, lower, upper):
"""
:type nums: List[int]
:type lower: int
:type upper: int
:rtype: List[str]
"""
ranges = []
prev = lower - 1
for i in range(len(nums) + 1):
if i == len(nums):
curr = upper + 1
else:
curr = nums[i]
if curr - prev > 2:
ranges.append("%d->%d" % (prev + 1, curr - 1))
elif curr - prev == 2:
ranges.append("%d" % (prev + 1))
prev = curr
return ranges
Download Missing Ranges.pyLeetcode 163 Missing Ranges problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.