-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissing-ranges.py
More file actions
27 lines (24 loc) · 978 Bytes
/
Copy pathmissing-ranges.py
File metadata and controls
27 lines (24 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import List
class Solution:
def findMissingRanges(self, nums: List[int], lower: int, upper: int) -> List[str]:
result = []
# Check if the given list is empty
if not nums:
result.append([lower, upper])
return result
# Check for missing numbers before the first element of the given list
if nums[0] > lower:
result.append([lower, nums[0]-1])
# Check for missing numbers between elements of the given list
for i in range(1, len(nums)):
if nums[i] - nums[i-1] > 1:
result.append([nums[i-1]+1, nums[i]-1])
# Check for missing numbers after the last element of the given list
if nums[-1] < upper:
result.append([nums[-1]+1, upper])
return result
solution = Solution()
print(solution.findMissingRanges([-1], -2, -1))
print(solution.findMissingRanges([-1], -1, -1))
print(solution.findMissingRanges([], 1, 1))
print(solution.findMissingRanges([0,1,3,50,75], 0, 77))