-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path163.py
More file actions
27 lines (26 loc) · 831 Bytes
/
163.py
File metadata and controls
27 lines (26 loc) · 831 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
class Solution:
def findMissingRanges(self, nums: List[int], lower: int, upper: int) -> List[str]:
if not nums:
if lower == upper:
return [str(lower)]
else:
return ["->".join([str(lower), str(upper)])]
if lower == upper:
return []
result =[]
i = lower
for n in nums:
if n == i:
i += 1
continue
else:
if i == n - 1:
result.append(str(i))
else:
result.append("->".join([str(i), str(n - 1)]))
i = n + 1
if i == upper:
result.append(str(i))
elif i < upper:
result.append("->".join([str(i), str(upper)]))
return result