Python 3 easy code: class Solution: def summaryRanges(self, nums: List[int]) -> List[str]: res = [] n = len(nums) i = 0 while i < n: start = nums[i] while i + 1 < n and nums[i + 1] == nums[i] + 1: i += 1 if start != nums[i]: res.append(str(start) + '->' + str(nums[i])) else: res.append(str(start)) i += 1 return res
Python 3 easy code:
class Solution:
def summaryRanges(self, nums: List[int]) -> List[str]:
res = []
n = len(nums)
i = 0
while i < n:
start = nums[i]
while i + 1 < n and nums[i + 1] == nums[i] + 1:
i += 1
if start != nums[i]:
res.append(str(start) + '->' + str(nums[i]))
else:
res.append(str(start))
i += 1
return res
Thank you! very good~
Don't you have class right now? LOLOLOL
haha yea lol I filmed it before the class though lol