Summary Ranges
来源:互联网 发布:淘宝消保30元加入条件 编辑:程序博客网 时间:2024/05/16 10:38
题目:
Given a sorted integer array without duplicates, return the summary of its ranges.
For example, given [0,1,2,4,5,7]
, return ["0->2","4->5","7"].
class Solution:
# @param {integer[]} nums
# @return {string[]}
def summaryRanges(self, nums):
ans = []
i = 0
while i<len(nums):
if i<len(nums)-1 and 1==nums[i+1]-nums[i]:
start = nums[i]
j = i+1
while(j<len(nums) and nums[j]-nums[i]==1):
i += 1
j += 1
end = nums[j-1]
ans.append(str(start)+"->"+str(end))
i = j
else:
ans.append(str(nums[i]))
i += 1
return ans
- Summary Ranges
- summary ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- Summary Ranges
- WEB前端网页返回代码常见值
- Android 百分比布局库(percent-support-lib) 解析与扩展
- Spring2.5学习4.1_AOP
- VS2012 加载工程失败PACKAGE “VISUAL C++ PACKAGE” FAILED TO LOAD
- strotol用法
- Summary Ranges
- 技能树
- 欢迎使用CSDN-markdown编辑器
- malloc()和calloc()和 new的功能介绍
- GRE句子填空题目实战技巧汇总
- [leetcode] 112.Path Sum
- 打开系统设置
- 5款瞬间复活Win7/8/10工具
- Shell脚本之监视指定进程的运行状态