228
# # @lc app=leetcode.cn id=228 lang=python3 # # [228] 汇总区间 # # @lc code=start class Solution: def summaryRanges(self, nums: List[int]) -> List[str]: if len(nums) <= 0: return [] res = [str(nums[0])] for i in range(1,len(nums)): if nums[i] - int(res[-1].split('->')[-1]) == 1: res[-1] = res[-1].split('->')[0] + '->' + str(nums[i]) else: res.append(str(nums[i])) return res # @lc code=end