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"].

Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.

Subscribe to see which companies asked this question

 
vector<string> summaryRanges(vector<int>& nums) {
vector<string> ret;
if (nums.size() == )
return ret;
int i = ;
int beg = nums[i];
while (i < nums.size())
{
if (i + == nums.size() || nums[i+] != nums[i] + )
{
if (nums[i] != beg)
ret.push_back(to_string(beg) + "->" + to_string(nums[i]));
else
ret.push_back(to_string(beg));
if(i + < nums.size())
beg = nums[i + ];
}
i++;
}
return ret;
}

Summary Ranges leetcode的更多相关文章

  1. Summary Ranges —— LeetCode

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

  2. summary ranges leetcode java

    问题描述: Given a sorted integer array without duplicates, return the summary of its ranges. For example ...

  3. leetcode面试准备:Summary Ranges

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

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

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

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

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

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

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

  7. Missing Ranges & Summary Ranges

    Missing Ranges Given a sorted integer array where the range of elements are [lower, upper] inclusive ...

  8. [LeetCode] Summary Ranges 总结区间

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

  9. C#解leetcode 228. Summary Ranges Easy

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

随机推荐

  1. java 数据设置和显示

    1. 首先设置ModelAndView 的值 @Override public ModelAndView handleRequest(HttpServletRequest arg0, HttpServ ...

  2. 关于Cookie中不过滤“=”号的方法

    近来做关于Cookie的加解密工作时遇到一个问题:当用cookie.getValue()方法获取Cookie的值时,结果遇到"="号时就会自动截断,后面的值就取不到了.这是因为Ja ...

  3. Pomelo的Filter

    在pomelo中,filter分为before filter和after filter.在一个请求到达Handler被处理之前,可以经过多个before Filter组成的filter链进行一些前置处 ...

  4. border-radius是向元素添加圆角边框的方法

    border-radius:10px; /* 所有角都使用半径为10px的圆角 */ border-radius: 5px 4px 3px 2px; /* 四个半径值分别是左上角.右上角.右下角和左下 ...

  5. Bootstrap入门(二十三)JS插件1:模态框

    Bootstrap入门(二十三)JS插件1:模态框 1.静态实例 2.动态实例 3.模态框的尺寸和效果 4.包含表单的模态框 模态框经过了优化,更加灵活,以弹出对话框的形式出现,具有最小和最实用的功能 ...

  6. 《你不知道的js》 ------1.作用域是什么

    相关定义 引擎:从头到尾负责整个JavaScript程序的编译及执行过程. 编译器:负责语法分析及代码生成等. 作用域:负责收集并维护由所有声明的标识符(变量)组成的一系列查询,并实施一套非常严格的规 ...

  7. 使用 Passenger +Apache扩展 Puppet,代替其Webrick的web框架

    使用 Passenger +Apache扩展 Puppet,代替其Webrick的web框架 1安装 yum install ruby-devel ruby-libs rubygems libcurl ...

  8. EntityFramework 简单入个门

    任何一个和数据相关的系统里,数据持久化都是一个不容忽视的问题. 一直以来,Java 平台出了很多 NB 的 ORM 框架,Hibernate.MyBatis等等..NET 平台上,ORM 框架这一块一 ...

  9. C++:C语言实现HTTP的GET和POST请求

    HTTP请求和IP/TCP 所谓的HTTP协议是基于IP/TCP协议的, 所以要获取远端的html数据只要创建socket对象就足够了: HTTP是基于IP/TCP加上了网络请求的固定格式, 比如: ...

  10. Codeforces758C

    C. Unfair Poll time limit per test:1 second memory limit per test:256 megabytes input:standard input ...