leetcode-Summary Ranges
2015-11-06 20:23
162 查看
Difficulty:
Easy
Given a sorted integer array without duplicates, return the summary of its ranges.
For example, given
Easy
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 { public: vector<string> summaryRanges(vector<int>& nums) { vector<string> res; if(nums.empty()) return res; int begin=0,end; int size=nums.size(); for(end=0;end<size;++end){ string temp(to_string(nums[begin])); while(end+1<size&&nums[end]+1==nums[end+1]) ++end; if(begin!=end) temp+="->"+to_string(nums[end]); res.push_back(temp); begin=end+1; } return res; } };
相关文章推荐
- Jquery常用的功能
- Android TextView中插入图片
- 《剑指offer》——矩形覆盖
- 无法定位程序输入点 @Idwinsock@initialization$qqrv 于动态链接库 indy60.bpl 上。
- 基数排序
- StarUML官网地址 http://staruml.io/
- 统计给定整数的二进制表示中1的个数
- 软件功能测试工具介绍
- 远端绑定Service第二篇之服务器端的Service
- Unity行为树
- 关于count()函数一些问题
- LeetCode:Single Number III
- 新人初来乍到
- 团队,不只是团队
- HDU 4503 数学
- UML总结之用例图
- 判断是否为邮箱,电话的匹配规则
- 《王爽——汇编语言》P172答案
- 欢迎使用CSDN-markdown编辑器
- log4j介绍和配置方法