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

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

 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. Random类(java.util)

    转自 Random类中实现的随机算法是伪随机,也就是有规则的随机.在进行随机时,随机算法的起源数字称为种子数(seed),在种子数的基础上进行一定的变换,从而产生需要的随机数字. 相同种子数的Rand ...

  2. JSP 隐藏对象

    [摘要]     隐藏对象用在jsp表达式和脚本中,不能直接用在jsp声明中,因为这些隐藏对象是容器在jspservice方法中定义的,在这个方法中定义的变量不能在jsp声明中使用.可以通过参数方法将 ...

  3. Mysql编辑工具中使用(Navicat查询结果显示行号)

    Mysql编辑工具中使用(Navicat查询结果显示行号) as rownum,a.roleId ) t where a.roleId='admin';

  4. Matlab生成动态链接库供C#调用

    1.首先在Matlab中编写一个或几个.m文件 2.然后在命令空间中输入命令:deploytool 3.修改工程名称,修改需要生成文件后缀 4.添加类,添加文件,然后点击生成.

  5. 四、mysql内置函数

    .字符串函数 concat('a','b'); 字符串拼接函数 ,,"我是A我是B"): 从指定位置开始替换指定长度的指定数据(起步为1) lower() 转小写 upper() ...

  6. 为什么要在<button>元素中添加type属性

    在HTML中<button> 标签定义一个按钮. <button type="button">Click Me!</button> 在 butt ...

  7. Firefly Http通信简单介绍

    原地址:http://www.9miao.com/question-15-54042.html 首先创建firefly工程,firefly-admin.py createproject httptes ...

  8. Unity3D 自动打包整个项目(以AssetBundle实现)

    原地址:http://blog.csdn.net/huang7jiao/article/details/18370653 需求: 在移动开发中,手动控制资源的加载.释放和热更新,是很有必要的. 而Un ...

  9. Host Definition

    Description: A host definition is used to define a physical server, workstation, device, etc. that r ...

  10. Binding to the Most Recent Visual Studio Libraries--说的很详细,很清楚

    Every version of Visual Studio comes with certain versions of the Microsoft libraries, such as the C ...