【刷题-LeetCode】228. Summary Ranges
- Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.
Example 1:
Input: [0,1,2,4,5,7]
Output: ["0->2","4->5","7"]
Explanation: 0,1,2 form a continuous range; 4,5 form a continuous range.
Example 2:
Input: [0,2,3,4,6,8,9]
Output: ["0","2->4","6","8->9"]
Explanation: 2,3,4 form a continuous range; 8,9 form a continuous range.
解 直接扫描
class Solution {
public:
vector<string> summaryRanges(vector<int>& nums) {
vector<string>ans;
int start = 0;
for(int i = 1; i <= nums.size(); ++i){
if(i == nums.size() || nums[i] != nums[i-1] + 1){
if(i == start+1){
ans.push_back(to_string(nums[start]));
}else{
ans.push_back(to_string(nums[start])+"->"+to_string(nums[i-1]));
}
start = i;
}
}
return ans;
}
};
【刷题-LeetCode】228. Summary Ranges的更多相关文章
- leetcode-【中等题】228. Summary Ranges
题目: 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its r ...
- [LeetCode] 228. Summary Ranges 总结区间
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- LeetCode 228. Summary Ranges (总结区间)
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- C#解leetcode 228. Summary Ranges Easy
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- Java for LeetCode 228 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 ...
- (easy)LeetCode 228.Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- Java [Leetcode 228]Summary Ranges
题目描述: Given a sorted integer array without duplicates, return the summary of its ranges. For example ...
- [leetcode]228. Summary Ranges区间统计
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- 【LeetCode】228. Summary Ranges 解题报告(Python)
[LeetCode]228. Summary Ranges 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/sum ...
随机推荐
- 【LeetCode】1029. Two City Scheduling 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 小根堆 排序 日期 题目地址:https://lee ...
- 【九度OJ】题目1473:二进制数 解题报告
[九度OJ]题目1473:二进制数 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1473 题目描述: 大家都知道,数据在计算机里中存 ...
- 【LeetCode】441. Arranging Coins 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 模拟计算 二分查找 数学公式 日期 题目地址:htt ...
- 【LeetCode】449. Serialize and Deserialize BST 解题报告(Python)
[LeetCode]449. Serialize and Deserialize BST 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/pro ...
- 【LeetCode】725. Split Linked List in Parts 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- Test for Job(poj3249)
Test for Job Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10209 Accepted: 2372 Des ...
- 人脸搜索项目开源了:人脸识别(M:N)-Java版
一.人脸检测相关概念 人脸检测(Face Detection)是检测出图像中人脸所在位置的一项技术,是人脸智能分析应用的核心组成部分,也是最基础的部分.人脸检测方法现在多种多样,常用的技术或工具大 ...
- 手机端h5页面 图片根据手势放大缩小
pinchzoom.js 这个插件可以简单的实现这一功能 <div class="big_pos_img page"> <div class="pinc ...
- Java实习生常规技术面试题每日十题Java基础(一)
目录 1.Java 的 "一次编写,处处运行"如何实现? 2.描述JVM运行原理. 3.为什么Java没有全局变量? 4.说明一下public static void main(S ...
- Java初学者作业——编写Java程序,输入一个学生的5门课程的成绩,求其平均分。
返回本章节 返回作业目录 需求说明: 编写Java程序,输入一个学生的5门课程的成绩,求其平均分.计算平均成绩,需要将每一门课程的成绩逐步累加到总成绩中,使用 for 循环实现,然后求出平均分. 实现 ...