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"].
题目大意:给一个有序数组,返回连续的区间范围。
public class Solution {
public List<String> summaryRanges(int[] nums) {
List<String> res = new ArrayList<>();
if(nums==null||nums.length==0){
return res;
}
for(int i=0;i<nums.length;i++){
int t = nums[i];
while(i<nums.length-1&&nums[i]+1==nums[i+1]){
i++;
}
String se = "" + t;
if(t!=nums[i])
se = t+"->"+nums[i];
res.add(se);
}
return res;
}
}
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 ...
随机推荐
- jquery生产和开发的区别
今天说一下jquery生产和开发的区别,在我们下载jquery的时候,会有两个下载链接,一个是jquery.min.js .迷你版 (生产),另一个是 jquery.js .开发版 .不知道的人可能就 ...
- 【转】iOS25彩票 幸运转盘
原文 : http://www.it165.net/pro/html/201409/21216.html 最终效果图: 各个view的关系图: 背景圆盘(需穴ky"http://www.it ...
- Objective-C中的分类与协议
分类 在谈分类之前,我们可以先探究下,OC中为什么出现分类这种机制,有什么好处? 假设你接到一个大项目:计算两个整数的和,差.接到任务的你马上动手.编写代码如下: #import <Founda ...
- Xcode4.4中,代码无法高亮、无法自动补全
1.代码无法高亮显示:2.代码不能自动补全,或者给出提示建议:(当然这个补全的功能我在设置当中是打开的状态)3.新建一个项目,代码还是依然没有高亮显示,但是有补全功能:4.然后我就在网络上搜索了相关的 ...
- 【cogs858】磁性链
[题目描述] 有N块编号为1~N的特殊磁石相互吸附组成一条磁性链,只有它们紧挨着时才会传递吸力,他们之间的吸力很大,如果我们要从N块相连的磁石中取出一块,那么需要消耗N-1个单位的能量,空缺处不再有吸 ...
- 『重构--改善既有代码的设计』读书笔记----Replace Data Value with Object
当你在一个类中使用字段的时候,发现这个字段必须要和其他数据或者行为一起使用才有意义.你就应该考虑把这个数据项改成对象.在开发初期,我们对于新类中的字段往往会采取简单的基本类型形式来保存,但随着我们开发 ...
- cetos 6.3 安装 apache+mysql+php
1.安装 apache 服务器 yum install httpd 启动服务 service httpd start or /etc/init.d/httpd start 2.安装 mysql 数 ...
- 关于alarm函数
#include<unistd.h> #include<signal.h> void handler() { printf("Hello\n"); sign ...
- ComboBoxEdit
1. 如何使其不可编辑 TextEditStyle 设置为:DisableTextEditor 2. 如何设置鼠标为手形 Cursor 设置为:Hand
- js手机站跳转
var yunzhuanhua_pc_domain = "http://www.域名.com#yht"; //PC站网址var yunzhuanhua_wap_domain = & ...