python
class Solution:
def summaryRanges(self, nums: List[int]) -> List[str]:
if not nums:
return []
result = []
start = nums[0]
for i in range(1, len(nums)):
if nums[i] != nums[i-1] + 1: # 发现不连续的情况
if start == nums[i-1]:
result.append(str(start))
else:
result.append(f"{start}->{nums[i-1]}")
start = nums[i]
# 最后一个区间
if start == nums[-1]:
result.append(str(start))
else:
result.append(f"{start}->{nums[-1]}")
return result