-
Notifications
You must be signed in to change notification settings - Fork 0
LC 0228 [E] Summary Ranges
Code with Senpai edited this page Mar 24, 2022
·
4 revisions
like merge intervals
class Solution:
def summaryRanges(self, nums: List[int]) -> List[str]:
res = []
for x in nums:
if res and res[-1][1] == x-1:
res[-1][1] = x
else:
res.append([x,x])
return [f'{str(a)}->{str(b)}' if a!=b else str(a) for a,b in res]
footer