Skip to content

Commit d76099b

Browse files
committed
Add Logic
1 parent 9b66d30 commit d76099b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Leetcode/Summary_Ranges/Summary_Ranges.py

+11
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,14 @@ def summaryRanges(self, nums):
44
:type nums: List[int]
55
:rtype: List[str]
66
"""
7+
result, i = [], 0
8+
while i < len(nums):
9+
start = nums[i]
10+
while i < len(nums) - 1 and (nums[i] + 1) == nums[i + 1]:
11+
i += 1
12+
if start != nums[i]:
13+
result.append(str(start) + "->" + str(nums[i]))
14+
else:
15+
result.append(str(nums[i]))
16+
i += 1
17+
return result

0 commit comments

Comments
 (0)