Summary Ranges leetcode
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的更多相关文章
- Summary Ranges —— LeetCode
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- summary ranges leetcode java
问题描述: Given a sorted integer array without duplicates, return the summary of its ranges. For example ...
- 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-【中等题】228. Summary Ranges
题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...
- Missing Ranges & Summary Ranges
Missing Ranges Given a sorted integer array where the range of elements are [lower, upper] inclusive ...
- [LeetCode] Summary Ranges 总结区间
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- C#解leetcode 228. Summary Ranges Easy
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
随机推荐
- Python中执行系统命令常见的几种方法--转载
Python中执行系统命令常见的几种方法 Python中执行系统命令常见的几种方法有: (1)os.system # 仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息 # 如果再命令行下执 ...
- 如何快速定位到Eclipse自动添加的TODO
把自动生成的// TODO ....前面加上todo,这样生成之后就会有编译错误,直接 ctrl+. 就到该位置了,可以删除todo留着// TODO ...,也可以ctrl+d删除一行: 不建议不生 ...
- 工厂模式在JS中的实践
.mytitle { background: #2B6695; color: white; font-family: "微软雅黑", "宋体", "黑 ...
- Android开发系列之adb常用命令
对于Android开发者来说,如果没有adb的帮助,那肯定就跟少了一只手那样别扭.其实笔者在刚刚学习Android开发的时候,也没有意识到adb的重要性.想想只要用IDE画出界面,然后实现后台的逻辑代 ...
- Bootstrap入门(二十七)JS插件4:标签页
Bootstrap入门(二十七)JS插件4:标签页 标签页的切换可以带动内容的变化 首先我们引入CSS文件 <link href="bootstrap.min.css" re ...
- javaScript基础详解(1)
javaScript基础详解 首先讲javaScript的摆放位置:<script> 与 </script> 可以放在head和body之间,也可以body中或者head中 J ...
- Redis 介绍与安装
Redis 是Key-Value 类型的内存数据库,支持多数据结构,性能非常出色,每秒处理十万次读写操作. 整个大致的过程是: 整个数据库加载到内存中,操作之,通过异步定期处理数据库数据的刷新到硬盘 ...
- 有趣的++i和i++
作为一个天天和代码“约会”的人来说i++和++i这玩意再熟悉不过了,因为使用频率太高了. 虽然如此,但也未必见得我们真的了解她,不妨猜猜下面的输出结果. #inlcude <stdio.h> ...
- MyEclipse - 解决 MyEclipse build workspace慢,validation javascript更慢的问题
在这个过程中对.projet文件进行了跟踪比对,总算发现这个Build的时候进行Validation是从哪里定义的了.似乎因为我的项目是基于ExtJS2.0.2的web project,所以会提示打开 ...
- iis7.0 ExtensionlessUrlHandler-Integrated-4.0解决方法
IIS7.0上部署网站,打开后500错误: 处理程序“ExtensionlessUrlHandler-Integrated-4.0” 在其模块列表中有一个错误模块“ManagedPipelineHan ...