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 ;
if(nums.size()< ) return res;
int i = ;
int n = nums.size();
while(i<n)
{
int j = ;
while(i+j<n && nums[i] == nums[i+j]-j) ++j;
res.push_back(j<=?to_string(nums[i]):to_string(nums[i])+"->"+to_string(nums[i+j-]));
i = i + j;
}
return res;
}
};

(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. 228. [LeetCode] Summary Ranges

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

  4. LeetCode Summary Ranges (统计有序数列范围)

    题意:给出个有序不重复数列(可能负数),用缩写法记录这个数列. 思路:找每个范围的起始和结束即可. class Solution { public: vector<string> summ ...

  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. 20145315 《Java程序设计》实验三实验报告

    实验三 敏捷开发与XP实践 实验内容 下载并学会使用git上传代码: 与同学结对,相互下载并更改对方代码,并上传: 实现代码的重载. 实验步骤 下载并用git上传代码: 1.下载并安装好git,在cm ...

  2. CentOS6.4 配置Haproxy

    Haproxy下载地址:http://pan.baidu.com/share/link?shareid=1787182295&uk=1829018343 也可用wget http://hapr ...

  3. FlyCapture2 VS2010 Configuration

    Add in the system Path: C:\Program Files (x86)\Point Grey Research\FlyCapture2\bin Project->Proje ...

  4. diff和patch配合使用(转载备用)

    Linux下diff与patch命令的配合使用 在Linux下,diff与patch命令配合使用可以进行简单的代码维护工作. [A] diffdiff命令用于比较文件的差异,可以用于制作patch文件 ...

  5. java ---运算符

    运算符简单来划分可以分为五大类:分别是算术运算符.关系运算符.逻辑运算符.三元运算符和赋值运算符.下面来分别介绍一下这几类运算符: 一.算术运算符 包含+  -  *  /  %  ++  --,这几 ...

  6. HDU 1016 Prime Ring Problem(经典DFS+回溯)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. c++ windows 获取mac地址

    c++ windows 获取mac地址 GetAdaptersInfo 用windows api获取mac地址和硬盘id编号 aa

  8. FlowVisor 安装

    参考:Github-FlowVisor-wiki 第一步 添加公钥: 命令: $ wget http://updates.onlab.us/GPG-KEY-ONLAB $ sudo apt-key a ...

  9. scapy 安装及简单测试

    关于scapy Scapy的是一个强大的交互式数据包处理程序(使用python编写).它能够伪造或者解码大量的网络协议数据包,能够发送.捕捉.匹配请求和回复包等等.它可以很容易地处理一些典型操作,比如 ...

  10. Xamarin Visual Studio无法debug

    在Visual Studio中,Target IOS Device下拉框是禁用状态,无法选择. Xamarin论坛中有不少关于这个问题的,如下面这个帖子: http://forums.xamarin. ...