题目:
题解:
class Solution:def summaryRanges(self, nums: List[int]) -> List[str]:def f(i: int, j: int) -> str:return str(nums[i]) if i == j else f'{nums[i]}->{nums[j]}'i = 0n = len(nums)ans = []while i < n:j = iwhile j + 1 < n and nums[j + 1] == nums[j] + 1:j += 1ans.append(f(i, j))i = j + 1return ans