Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def summaryRanges(self, nums: List[int]) -> List[str]:
- ans = []
- cur_range = None
- def pop_cur_range() -> None:
- nonlocal ans, cur_range
- if cur_range is None:
- return
- if cur_range[0] == cur_range[1]:
- ans.append(f"{cur_range[0]}")
- else:
- ans.append(f"{cur_range[0]}->{cur_range[1]}")
- cur_range = None
- for n in nums:
- if cur_range is not None and cur_range[1] + 1 != n:
- pop_cur_range()
- if cur_range is None:
- cur_range = [n, n]
- cur_range[1] = n
- pop_cur_range()
- return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement