【LeetCode 228_数组】Summary Ranges
vector<string> summaryRanges(vector<int>& nums)
{
int nums_len = nums.size();
vector<string> res;
if (nums_len == )
return res; for (int i = ; i < nums_len;) {
int start = i, end = i;
while (end + < nums_len && nums[end + ] == nums[end] + ) end++;
if (end > start)
res.push_back(to_string(nums[start]) + "->" + to_string(nums[end]));
else
res.push_back(to_string(nums[start]));
i = end + ;
}
return res;
}
【LeetCode 228_数组】Summary Ranges的更多相关文章
- 【LeetCode】228. Summary Ranges 解题报告(Python)
[LeetCode]228. Summary Ranges 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/sum ...
- leetcode面试准备:Summary Ranges
1 题目 Given a sorted integer array without duplicates, return the summary of its ranges. For example, ...
- 【刷题-LeetCode】228. Summary Ranges
Summary Ranges Given a sorted integer array without duplicates, return the summary of its ranges. Ex ...
- LeetCode OJ:Summary Ranges(概括区间)
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- 【LeetCode】228 - Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- leetcode-【中等题】228. Summary Ranges
题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...
- LeetCode Monotone Stack Summary 单调栈小结
话说博主在写Max Chunks To Make Sorted II这篇帖子的解法四时,写到使用单调栈Monotone Stack的解法时,突然脑中触电一般,想起了之前曾经在此贴LeetCode Al ...
- 【持续更新】leetcode算法-数组篇
会在近期陆续地完成数组篇的整理,希望对找工作的小伙伴有所帮助. 1.Two Sum:两数相加为一固定值,求其下标.一次遍历数组,用一个hash表存储已经访问过的数及其下标,对于新访问的数value ...
- Missing Ranges & Summary Ranges
Missing Ranges Given a sorted integer array where the range of elements are [lower, upper] inclusive ...
随机推荐
- Shape-inside css新属性 几何图形的实现
https://www.w3cplus.com/css3/css-shapes-101.html
- 条件编译#ifdef的妙用详解
c语言中条件编译相关的预编译指令,包括 #define.#undef.#ifdef.#ifndef.#if.#elif.#else.#endif.defined. #define ...
- thinkerCMS是一款thinkphp写的微型cms框架可以参考下
http://www.thinkphp.cn/code/1764.html thinkphp官网thinkercms介绍 http://cms.thinke ...
- GRUB2 分析 (一)
GRUB是目前较流行启动引导程序.其第二版被主流Linux发行版所包括.本文将探索和分析GRUB的设计和实现机制. boot.S是第一个研究对象,因为boot.S将被编译成boot.img(512字节 ...
- 20135302魏静静——linux课程第八周实验及总结
linux课程第八周实验及总结 实验及学习总结 1. 进程切换在内核中的实现 linux中进程切换是很常见的一个操作,而这个操作是在内核中实现的. 实现的时机有以下三个时机: 中断处理过程(包括时钟中 ...
- MySQL MERGE存储引擎 简介及用法
MERGE存储引擎把一组MyISAM数据表当做一个逻辑单元来对待,让我们可以同时对他们进行查询.构成一个MERGE数据表结构的各成员MyISAM数据表必须具有完全一样的结构.每一个成员数据表的数据列必 ...
- webservice的cxf和spring整合客户端开发
1.新建一个java项目 2.导入cxf相关的jar包,并部署到项目中 3.用命令生成客户端使用说明文档 wsdl2java -p com.xiaostudy -d . http://127.0.0. ...
- 在线前端 样式和js
bootstrap+ jquery <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstra ...
- 关于Spring Test 小结
1.>public class CustomerPackagePrealertControllerTest extends WebSpringBaseTest{} 2.> @WebApp ...
- Linux Shell参数替换
Linux Shell参数替换 2013-06-03 10:01 by 轩脉刃, 1816 阅读, 0 评论, 收藏, 编辑 Bash中的符号的作用是参数替换,将参数名替换为参数所代表的值.对于 来说 ...