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 ...
随机推荐
- Eclipse中javascript文件 clg 变为console.log();
Eclipse中javascript文件 clg 变为console.log(); window>preferance>JavaScript>Editor>Templates ...
- 将[4,3,2,5,4,3]分割成[4,3,2]、[5,4,3]两个List的算法
将[4,3,2,5,4,3]分割成[4,3,2].[5,4,3]两个List的算法 package com.srie.test; import java.util.ArrayList; import ...
- Raphael的鼠标over move out事件
Raphael的鼠标over move out事件 <%@ page language="java" contentType="text/html; charset ...
- 让EFCore更疯狂些的扩展类库(一):通过json文件配置sql语句
前言 EF通过linq和各种扩展方法,再加上实体模型,编写数据库的访问代码确实是优美.舒服,但是生成的sql不尽如意.性能低下,尤其是复杂些的逻辑关系,最终大家还是会回归自然,选择能够友好执行sql语 ...
- Eclipse安装git
用Eclipse开发,如果需要团队协作,git作为分布式版本管理工具就是个比较好的选择.下面简单介绍一下git插件的安装方法: 1.Help -- install new software 打开插件安 ...
- page cache 与free
我们经常用free查看服务器的内存使用情况,而free中的输出却有些让人困惑,如下: 先看看各个数字的意义以及如何计算得到: free命令输出的第二行(Mem):这行分别显示了物理内存的总量(tota ...
- 关于Task的一点思考和建议
前言 本打算继续写SQL Server系列,接下来应该是死锁了,但是在.NET Core项目中到处都是异步,最近在写一个爬虫用到异步,之前不是很频繁用到异步,当用到时就有点缩手缩尾,怕留下坑,还是小心 ...
- Unity编程标准导引-2.2Unity中的基本概念
2.2Unity中的基本概念 上述介绍提到了几个概念:游戏对象.场景.资源.相机,这个小节我们来深入了解,同时进行一些实践性操作.不过首先,我们需要大概了解一下Unity的工程文件夹. 2.2.1工程 ...
- asp.net MVC4总结
MVC4构建例子 新建MVC4项目 在项目工程下面的App_Data文件夹下面添加新建项->数据-> Sql server 数据库文件Movies.mdf 新建movies.cs模型类 ...
- Codeforces 719B Anatoly and Cockroaches
B. Anatoly and Cockroaches time limit per test:1 second memory limit per test:256 megabytes input:st ...