标签:code bsp 双指针 ima 汇总 描述 pen img end
题目描述:
第一次提交:双指针 O(N)
class Solution: def summaryRanges(self, nums: List[int]) -> List[str]: #first = 0 last = 0 res = [] while last!=len(nums): first = last while last+1<len(nums) and nums[last+1]-nums[last]==1: last += 1 if first == last: res.append(str(nums[first])) else: res.append("{}->{}".format(nums[first],nums[last])) last += 1 return res
标签:code bsp 双指针 ima 汇总 描述 pen img end
原文地址:https://www.cnblogs.com/oldby/p/11624248.html