Skip to content

Commit 8ab4398

Browse files
committed
2019-07-03
1 parent c5aeb36 commit 8ab4398

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Solution(object):
2+
def findMissingRanges(self, nums, lower, upper):
3+
"""
4+
:type nums: List[int]
5+
:type lower: int
6+
:type upper: int
7+
:rtype: List[str]
8+
"""
9+
# if not nums:
10+
# if lower == upper:
11+
# return [str(lower)]
12+
# else:
13+
# return [str(lower) + "->" + str(upper)]
14+
start = lower
15+
end = lower
16+
res = []
17+
for i in range(len(nums)):
18+
if nums[i] == end:
19+
start, end = nums[i] + 1, nums[i] + 1
20+
21+
elif nums[i] > end:
22+
end = max(end, nums[i] - 1)
23+
24+
if end != start:
25+
res.append(str(start) + "->" + str(end))
26+
else:
27+
res.append(str(start))
28+
29+
start, end = nums[i] + 1, nums[i] + 1
30+
31+
if start < upper:
32+
res.append(str(start) + "->" + str(upper))
33+
elif start == upper:
34+
res.append(str(start))
35+
36+
return res

0 commit comments

Comments
 (0)