LeetCode Summary Ranges (统计有序数列范围)
题意:给出个有序不重复数列(可能负数),用缩写法记录这个数列。
思路:找每个范围的起始和结束即可。
class Solution {
public:
vector<string> summaryRanges(vector<int>& nums) {
if(nums.empty()) return vector<string>();
vector<string> vect;
for(int i=; i<nums.size(); i++)
{
int s=nums[i], e;
while(i+<nums.size()&&nums[i]+==nums[i+]) i++;
e=nums[i];
if(s<e) vect.push_back(to_string(s)+"->"+to_string(e));
else vect.push_back(to_string(s));
}
return vect;
}
};
AC代码
LeetCode Summary Ranges (统计有序数列范围)的更多相关文章
- [LeetCode] Summary Ranges 总结区间
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- LeetCode——Summary Ranges
Description: Given a sorted integer array without duplicates, return the summary of its ranges. For ...
- (leetcode)Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- 228. [LeetCode] Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- leetcode面试准备:Summary Ranges
1 题目 Given a sorted integer array without duplicates, return the summary of its ranges. For example, ...
- 【LeetCode】228. Summary Ranges 解题报告(Python)
[LeetCode]228. Summary Ranges 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/sum ...
- 【刷题-LeetCode】228. Summary Ranges
Summary Ranges Given a sorted integer array without duplicates, return the summary of its ranges. Ex ...
- [LeetCode] Missing Ranges 缺失区间
Given a sorted integer array where the range of elements are [0, 99] inclusive, return its missing r ...
- leetcode-【中等题】228. Summary Ranges
题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...
随机推荐
- 2015-4-2的阿里巴巴笔试题:乱序的序列保序输出(bit数组实现hash)
分布式系统中的RPC请求经常出现乱序的情况.写一个算法来将一个乱序的序列保序输出.例如,假设起始序号是1,对于(1, 2, 5, 8, 10, 4, 3, 6, 9, 7)这个序列,输出是:123, ...
- oracle linux了解基本命令行
1. Linux的版本:核心(kernel)版本和发行(distribution)版本 2. 复制.删除和移动文件的命令 cp [选项] 源文件或目录 目标文件或目录 -R,-r ...
- iOS开发学习路线图
很多初学iOS开发的人会经常问:“我想学iOS应该从何入手呢?”.作为一个做了2年多各种iOS开发的程序员,只想写写自己的一些心得体会,好和体验与不好的体验.写的不好,请多包涵.希望能起到抛砖引玉的作 ...
- SQL学习中(一)序列
序列可以理解数值序列生成器,通俗的说是按照已经设定的规则自动产生数据的方案对象.--SQL SERVER不支持 个人认为序列类似于SQLSERVER中的identity(1,1),可以用于在表中添加数 ...
- Telerik 控件事例(鼠标拖动行,拖动列,设置行对齐,行宽,是否显示)
People.cs using System;using System.Collections.Generic;using System.Data;using System.Linq;using Sy ...
- 使用Pod集成Bugtags填坑记
最近某朋友的朋友的创业公司新出了一个工具叫Bugtags,说是可以让APP测试变得so easy,于是动手来做1.1.0的版本集成,先把WEB首页贴在下面,感兴趣的同学可以去look一下:https: ...
- SQL注入中的WAF绕过技术
目录 1.大小写绕过 2.简单编码绕过 3.注释绕过 4.分隔重写绕过 5.Http参数污染(HPP) 6.使用逻辑运算符 or /and绕过 7.比较操作符替换 8.同功能函数替换 9.盲注无需or ...
- uva 10051
将每一个分解为六个两面的 简单地dp 回溯输出路径..... #include <cstdio> #include <cstring> #include <cmath&g ...
- stl map高效遍历删除的方法
for(:iter!=mapStudent.end():) { if((iter->second)>=aa) { //满足删除条件,删除当前结点,并指 ...
- FZU-1921+线段树
简单的线段树. 记录MinVal 和 相应的ID即可 /* 线段树 */ #include<stdio.h> #include<string.h> #include<st ...