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 ...
随机推荐
- CSS样式权值
内联样式表(InLine style)>内部样式表(Internal style sheet)>外部样式表(External style sheet) 例外:但如果外部样式表放在内部样式表 ...
- sublime的js调试环境(基于node环境)
很多的语言都有控制台,都要专门的ide,js,用sublime在node的环境下,可以配置console, 如何配置?首先,要有node的环境,下载安装,还要安装到c盘才行,然后找到'工具(tool) ...
- (转)ecshop刷新页面出现power by ecshop和链接的解决办法
当小伙伴在使用echop模板进行修改的时候,如果你删掉底部自带版权后,再调试程序刷新界面的时候,时不时就会冒出一个power by ecshop,而且是带有链接的,很不舒服,所以需要去掉,下面是最简单 ...
- Echarts使用随笔(2)-Echarts中mapType and data
本文出处:http://blog.csdn.net/chenxiaodan_danny/article/details/39081071 series : [ { ...
- opencar二次开发常用代码
<?php //创建Registry对象 //注册所有公共类 //创建Front类对象,作为请求分发器(Dispatcher) //根据用户请求(url)创建控制器对象及其动作. // 在Fro ...
- centos 6.x 安装redis
1.yum 安装 yum install redis 如果提示找不到包的话 可以yum install epel-release 先安装epel第三方库 2.源码安装 https://redis ...
- cocos2dx JAVA,C++互相调用函数
C++调用JAVA 例子 #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "platform/android/jni/Jni ...
- 如何:在 StackPanel 和 DockPanel 之间进行选择
虽然可以使用 DockPanel 或 StackPanel 来堆叠子元素,但这两个控件并不总是会产生相同的结果. 例如,子元素的放置顺序可能会影响 DockPanel 中子元素的大小,但不会影响 St ...
- shell脚本获取mysql插入数据自增长id的值
shell脚本获取mysql插入数据自增长id的值 在shell脚本中我们可以通过last_insert_id()获取id值,但是,需要注意的是,该函数必须在执行插入操作的sql语句之后,立即调用,否 ...
- 入门4:PHP 语法基础1
一.PHP标记符 1.PHP页面中 以<?php 开头, ?>结尾,纯PHP页面结尾可以不写?> 2.在HTML页面插入PHP代码,必须有?>结尾.代码如下: <!DO ...