LeetCode(228) Summary Ranges
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;
auto start=nums.begin(); while(start != nums.end())
{
auto end=start;
end++;
string tem="";
int x=*start;
itos(tem,x);
while(end != nums.end() && *end - *start == 1){
start++;
end++;
}
if(x == *start)
res.push_back(tem);
else
{
tem+="->";
itos(tem,*start);
res.push_back(tem);
}
start++;
}
return res;
}
void itos(string &str,int k) //主要是如何快速转换成字符串!!!
{
ostringstream oss;//创建一个流 oss<<k;//把值传递如流中 str+=oss.str();
}
};
LeetCode(228) Summary Ranges的更多相关文章
- [LeetCode] 228. Summary Ranges 总结区间
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- C#解leetcode 228. Summary Ranges Easy
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- LeetCode 228. Summary Ranges (总结区间)
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- Java for LeetCode 228 Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- (easy)LeetCode 228.Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- Java [Leetcode 228]Summary Ranges
题目描述: Given a sorted integer array without duplicates, return the summary of its ranges. For example ...
- [leetcode]228. Summary Ranges区间统计
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- 【LeetCode】228. Summary Ranges 解题报告(Python)
[LeetCode]228. Summary Ranges 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/sum ...
- leetcode-【中等题】228. Summary Ranges
题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...
随机推荐
- arguments.callee
arguments.callee在哪个函数中运行,他就代表哪个函数,一般在匿名函数中.在匿名函数中有时需要自己调用自己,但是由于是匿名函数,没有名字,所以可以用arguments.callee来代替匿 ...
- MVC的传递数据的方法
1.使用ViewBag #region 0.2 Action方法 + ActionResult Index2() /// <summary> /// Action方法 /// </s ...
- 【django入门教程】Django的安装和入门
很多初学django的朋友,都不知道如何安装django开发以及django的入门,今天小编就给大家讲讲django入门教程. 注明:python版本为3.3.1.Django版本为1.5.1,操作系 ...
- CGAffineTransformMakeTranslation和CGAffineTransformTranslate
分类: ios基础2013-01-06 22:05 15513人阅读 评论(2) 收藏 举报 1.CGAffineTransformMakeTranslation每次都是以最初位置的中心点为起始参照 ...
- eclipse安装spring和hibernate插件经验
看网上的教程有时候不一定凑效,我是自己摸索的(看过尚硅谷的SSH视频),很多时候会安装不成功(或者安装结果与视频讲述不一致),但是安装过后,查看eclispe插件,会发现已经安装了(springIDE ...
- ubuntu下的wps不能使用中文.
首先如果wps不能用中文的话应该是 excell ppt word 都不能用 . 我的办法需要改三个文件 . 先后打开这三个文件 . xpower@xpower-CW65S:~$ sudo vim / ...
- BZOJ 2241 打地鼠
暴力. 这怎么这么快.... #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- Python OpenCV —— Border
关于border的部分,边缘处理. # -*- coding: utf-8 -*- """ Created on Wed Sep 28 00:58:51 2016 @au ...
- Android布局居中的几种做法
Android的布局文件中,如果想让一个组件(布局或View)居中显示在另一个布局(组件)中,可以由这么几种做法: android:layout_gravity android:gravity and ...
- 微信 关闭手机微信内置浏览器的js
WeixinJSBridge.call('closeWindow');