题意:给出个有序不重复数列(可能负数),用缩写法记录这个数列。

思路:找每个范围的起始和结束即可。

 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 (统计有序数列范围)的更多相关文章

  1. [LeetCode] Summary Ranges 总结区间

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

  2. LeetCode——Summary Ranges

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

  3. (leetcode)Summary Ranges

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

  4. 228. [LeetCode] Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...

  5. leetcode面试准备:Summary Ranges

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

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

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

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

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

  8. [LeetCode] Missing Ranges 缺失区间

    Given a sorted integer array where the range of elements are [0, 99] inclusive, return its missing r ...

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

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

随机推荐

  1. Linux vi 中搜索关键字

    当你用vi打开一个文件后,因为文件太长,如何才能找到你所要查找的关键字呢? 在vi里可没有菜单-〉查找 不过没关系,可以在命令模式下敲斜杆( / )这时在状态栏(也就是屏幕左下脚)就出现了 “/” 然 ...

  2. 不得不知道的Python字符串编码相关的知识

    开发经常会遇到各种字符串编码的问题,例如报错SyntaxError: Non-ASCII character 'ascii' codec can't encode characters in posi ...

  3. C语言socket编程--每日签到

    前几天写了个python的每日签到,你运行还得借助crontab,很是不爽.....正好前几天看了个关于c编写daemon进程,加上自己那点可怜的socket知识,于是我们重操旧页,C语言版的每日签到 ...

  4. Beaglebone Back学习一(开发板介绍)

    随着开源软件的盛行.成熟,开源硬件也迎来了春天,先有Arduino,后有Raspherry Pi,到当前的Beaglebone .相信在不久的将来,开源项目将越来越多,越来越走向成熟.         ...

  5. Could not retrieve mirrorlist http://mirrorlist.centos.org || PYCURL ERROR 6

    yum:Could not retrieve mirrorlist http://mirrorlist.centos.org || PYCURL ERROR 6 通过centos安装openldap的 ...

  6. C# list 筛选FindAll

    例如:参数a.list b.ModelId:根据ModelId参数进行筛选 /// <summary> /// 根据ModelId筛选查询出对应的数据 /// </summary&g ...

  7. 2329: [HNOI2011]括号修复 - BZOJ

    恶心的splay,打标记的时候还有冲突,要特别小心 上次写完了,查了半天没查出错来,于是放弃 今天对着标程打代码,终于抄完了,我已经不想再写了 const maxn=; type node=recor ...

  8. 2337:[HNOI2011]XOR和路径 - BZOJ

    昨天才做了一道高斯消元,一下要精度判断,一下又不要精度判断 主要是思路很重要 很容易想到每一个二进制位算一个概率,然后求和,设f[i]为走到从i走到n这一个二进制位为1的概率 f[i]:=∑{f[j] ...

  9. Firefly 配置说明!

    原地址:http://www.9miao.com/question-15-43023.html 下图一一个典型的config.json的配置:<ignore_js_op> "db ...

  10. python繁体中文到简体中文的转换

      处理中文字符串遇到了繁体和简体中文的转换,python版: 1.下载zh_wiki.py及langconv zh_wiki.py:https://github.com/skydark/nstool ...