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"].

Credits:

==============

题目,返回数组范围的  集合.

思路:

模拟整个过程,利用标准库中提供了to_string函数,

就没有什么大问题.

============

code如下:

class Solution {
public:
vector<string> summaryRanges(vector<int>& nums) {
vector<string> re;
if(nums.empty()) return re;
int n = nums.size();
for(int i = ;i<n;){
//string tt = to_string(nums[i]);
string t = to_string(nums[i])+"->";
int j = i+;
while(j<n && nums[j]==nums[j-]+){
j++;
}
if(i==(n-) || j==(i+)){
re.push_back(to_string(nums[i]));
}else{
t+=to_string(nums[j-]);
re.push_back(t);
}
i = j;
}///for
for(auto i:re) cout<<i<<endl;
return re;
}
};

228. Summary Ranges的更多相关文章

  1. leetcode-【中等题】228. Summary Ranges

    题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...

  2. 【LeetCode】228. Summary Ranges 解题报告(Python)

    [LeetCode]228. Summary Ranges 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/sum ...

  3. 【刷题-LeetCode】228. Summary Ranges

    Summary Ranges Given a sorted integer array without duplicates, return the summary of its ranges. Ex ...

  4. Java for LeetCode 228 Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  5. LeetCode(228) Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  6. (easy)LeetCode 228.Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  7. 【LeetCode】228 - Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  8. Java [Leetcode 228]Summary Ranges

    题目描述: Given a sorted integer array without duplicates, return the summary of its ranges. For example ...

  9. C#解leetcode 228. Summary Ranges Easy

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

随机推荐

  1. 六个超大规模Hadoop(前景)

    http://cloud.zol.com.cn/441/4415033_all.html 希望自己可以尽快把Hadoop学好

  2. ZOJ 1045 HangOver

    原题链接 题目大意:叠扑克牌,给出伸出长度,问最多需要几张扑克牌. 解法:循环累加.退出循环后向上取整输出. 参考代码: #include<iostream> using namespac ...

  3. mysql 5.5及以前版本的编码问题“Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC...' for column 'realname' at row 1”

    遇到这个问题,所有的编码都设为utf8了,还是没有用,各种乱码,后来发现这是mysql自己的问题,它在5.5及之前的版本只支持3字节的utf8编码,出现4字节的utf编码时出现错误,参考: http: ...

  4. MySql 查询一周内最近7天记录

    本周内:select * from wap_content where week(created_at) = week(now) 查询一天:select * from table where to_d ...

  5. 新浪代码部署手册 git管理工具

    目前新浪云上的应用支持通过Git和SVN来部署代码. Git仓库地址 https://git.sinacloud.com/YOUR_APP_NAME SVN仓库地址 https://svn.sinac ...

  6. Metasploit连接postgres数据库

    操作环境为Kali虚拟机 root@kali:~# apt-get install postgresql 启动服务 root@kali:~# service postgresql start [ ok ...

  7. NetStatusEvent info对象的状态或错误情况的属性

      代码属性 级别属性 意义 "NetStream.Buffer.Empty" "status"  数据的接收速度不足以填充缓冲区.数据流将在缓冲区重新填充前中 ...

  8. PgSQL · 追根究底 · WAL日志空间的意外增长

    问题出现 我们在线上巡检中发现,一个实例的pg_xlog目录,增长到4G,很是疑惑.刚开始怀疑是日志归档过慢,日志堆积在pg_xlog目录下面,未被清除导致.于是检查归档目录下的文件,内容如下.但发现 ...

  9. Jquery easyui的validatebox控件和正则表达式

    http://blog.csdn.net/dandanzmc/article/details/36421465 仔细观察jquery.validatebox.js文件,会发现它的验证其实还是采用的正则 ...

  10. openjudge-回文串判断【递归】

    回文串判断 总时间限制: 1000ms 内存限制: 65536kB 描述 任意给定一个非空的字符串,判断其是否是回文串.回文串是指正向看和反向看均相等的串,如AbcDcbA和cDDc.如果是回文串,则 ...