classSolution: def summaryRanges(self, nums: List[int]) -> List[str]: if len(nums) ==0: return [] ans = [] ans.append([nums[0], nums[0]])
for i in range(1, len(nums)): if nums[i] == ans[-1][1] + 1: ans[-1][1] = nums[i] else: ans.append([nums[i], nums[i]]) ret = [] for (s,e) in ans: if s == e: ret.append(str(s)) else: ret.append("{}->{}".format(s,e)) return ret