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 ...
随机推荐
- POJ 2763
题意:给一个数,边之间有权值,然后两种操作,第一种:求任意两点的权值和,第二,修改树上两点的权值. #pragma comment(linker, "/STACK:1024000000,10 ...
- xlistview的XML(头)xlistview_header
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...
- JS事件大全
橙色表示“非常常用” 绿色表示“常用” onClick IE3|N2|O3 鼠标点击事件,多用在某个对象控制的范围内的鼠标点击 onDblClick IE4|N4|O 鼠标双击事件 onMouseD ...
- 关押罪犯(noip2010)
解法: (1)搜索(30分) (2)二分(此题属于最大值最小问题) (3)贪心+并查集 下面着重说一下“贪心+并查集” 因为有A.B两座监狱,每个犯人不是在A,就是在B监狱. 至于每个犯人在那个监狱, ...
- allegro si(三)
前言:si的教程市面上是很少的,layout是台湾工程师的强项,还有就是日本人,国人爱用AD. si的教程中靠谱的还是张飞的收费课程,还有华为的资料. Cadence SI 仿真实验步骤如下: 1.熟 ...
- python3 nonlocal vs global
考虑这样一个python程序: x = 12 def func(): x = 1 func() print(x) 输出为:x = 12 因为函数内部定义的x被认为只属于局部作用域,为了表明我么引用的是 ...
- BZOJ 3398 牡牛和牝牛
dp. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- 在config文件输入特殊字符
今天遇到要在config文件中配置一个包含引号,尖括号的特殊字符的问题,config文件不支持转义字符,我开始发动自己的脑子想,想出一个蹩脚的方法,用其他的字符替换比如&,?,!,问题倒是解决 ...
- HTTP Live Streaming直播(iOS直播)技术分析与实现
前些日子,也是项目需要,花了一些时间研究了HTTP Live Streaming(HLS)技术,并实现了一个HLS编码器HLSLiveEncoder,当然,C++写的.其功能是采集摄像头与麦克风,实时 ...
- 重学STM32---(五)ADC
这两天把外部中断和ADC看了下,个人感觉外部中断不是很难,也就没有把记下来了,毕竟写这个挺浪费时间.ADC是比较复杂的,如果想让完全自由的运用ADC必须经过多次实践可能才可以.由于已经学过库函数,也就 ...