(leetcode)Summary Ranges
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的更多相关文章
- [LeetCode] Summary Ranges 总结区间
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- LeetCode——Summary Ranges
Description: Given a sorted integer array without duplicates, return the summary of its ranges. For ...
- 228. [LeetCode] Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- LeetCode Summary Ranges (统计有序数列范围)
题意:给出个有序不重复数列(可能负数),用缩写法记录这个数列. 思路:找每个范围的起始和结束即可. class Solution { public: vector<string> summ ...
- 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] Missing Ranges 缺失区间
Given a sorted integer array where the range of elements are [0, 99] inclusive, return its missing r ...
- leetcode-【中等题】228. Summary Ranges
题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...
随机推荐
- topcoder SRM 592 DIV2 LittleElephantAndPermutationDiv2
#include <iostream> #include <vector> #include <algorithm> #include <iterator&g ...
- javascript中字符串常用操作总结、JS字符串操作大全
字符串的操作在js中非常频繁,也非常重要.以往看完书之后都能记得非常清楚,但稍微隔一段时间不用,便会忘得差不多,记性不好是硬伤啊...今天就对字符串的一些常用操作做个整理,一者加深印象,二者方便今后温 ...
- OC中的属性、方法及内存管理
普通方法:关注(代表)对象可以”干什么”,过程中需要实例变量.-(void)show;输出 … 访问属性 属性:属性专门处理实例变量.(程序执行过程当中) 初始化方法:一创建对象(第一时间 ...
- A trip through the Graphics Pipeline 2011_03
At this point, we’ve sent draw calls down from our app all the way through various driver layers and ...
- PHP里用户密码的回复和管理
1). In /etc/my.ini, add skip-grant-tables 2). mysql -u root -p (no password required) mys ...
- Tesseract 对验证码的识别原理和实现步骤
一. Steps: 学习图片库--->处理图片(初步处理)--->校正.学习图片 二. Tesseract: 1. 采集图片库(一般每个出现的字符出现20次左右识别效果比较好),根据图片特 ...
- 关于APP接口设计
最近一段时间一直在做APP接口,总结一下APP接口开发过程中的注意事项: 1.效率:接口访问速度 APP有别于WEB服务,对服务器端要求是比较严格的,在移动端有限的带宽条件下,要求接口响应速度要快,所 ...
- 读取C#AssemblyInfo文件中的AssemblyVersion中的值
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); 1.程序集的版本信息由下面四个值组成:主 ...
- Memcache 提高缓存命中率
最近手上某个项目跟新代码,新的代码里大量采用memcahce作为缓存.所以开始深入了解memcache的内存分配策略.以前就听说有个PHP写的memcache监控脚本,在网上搜索了一下,果断下载下来用 ...
- 4 bytes (32 bits) or 8 bytes (64 bits)
Computer Systems A Programmer's Perspective Second Edition BusesRunning throughout the system is a c ...