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. 英语语法最终珍藏版笔记-6“情态动词+have+ done”的含义

    “情态动词+have+ done”的含义 1.Must have done的含义.“must have+过去分词”表示对过去的推测,意思是“一定已经,想必已经,准是已经….”,只用于肯定句中.例如: ...

  2. Javascript中最常用的61段经典代码

    1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键<table border oncontextmenu= ...

  3. (转)8 Tactics to Combat Imbalanced Classes in Your Machine Learning Dataset

    8 Tactics to Combat Imbalanced Classes in Your Machine Learning Dataset by Jason Brownlee on August ...

  4. (转) ICCV 2015:21篇最火爆研究论文

          ICCV 2015:21篇最火爆研究论文 ICCV 2015: Twenty one hottest research papers   “Geometry vs Recognition” ...

  5. Linux-某电商网站流量劫持案例分析与思考

    [前言] 自腾讯与京东建立了战略合作关系之后,笔者网上购物就首选京东了.某天在家里访问京东首页的时候突然吃惊地发现浏览器突然跳到了第三方网站再回到京东,心里第一个反应就是中木马了. 竟然有这样的事,一 ...

  6. 动态加载dll,并创建类对象放入到list中。

    private List<IVisualControlsPlug> visualPlugs = new List<IVisualControlsPlug>(); public ...

  7. Android调用系统分享功能以及createChooser的使用

    工程结构 //效果图 点击测试分享                                                                                   ...

  8. JS的Document属性和方法小结

    Document想必大家并不陌生吧,在使用js的过程中会经常遇到它,那么它有哪些属性.哪些方法,在本文将以示例为大家详细介绍下,希望对大家有所帮助 document.title //设置文档标题等价于 ...

  9. HTML相对路径 当前目录、上级目录、根目录、下级目录表示法

    文件引用时经常需要用到相对目录.如(js,css,图片等) "./"  ---------       源代码所在的当前目录(可省略) "../"  ----- ...

  10. 【转】C#程序打包安装部署之添加注册表项

    今天为大家整理了一些怎样去做程序安装包的具体文档,这些文档并不能确保每个人在做安装包的时候都能正确去生成和运行,但是这些文档的指导作用对于需要的朋友来说还是很有必要的,在实际产品的安装部署过程中可能有 ...