Summary Ranges —— LeetCode
2024-10-19 11:50:20
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;
}
}
最新文章
- Hiberbate
- git merge git pull时候遇到冲突解决办法git stash
- Windows Phone8.1 SDK中的新控件
- document.execCommand()命令小计
- Joson的简单用法
- 【Stage3D学习笔记续】山寨Starling(十一):Touch事件体系
- 注册表被篡改,请重新安装应用程序 acdphotoEdit
- jquery之属性操作
- JavaScript数组去重方法及测试结果
- 关于HashSet集合add元素
- bounding box的简单理解
- Codeforces 746F Music in Car
- [C#]RichTextBox实现拖放
- 背水一战 Windows 10 (57) - 控件(集合类): ListViewBase - 增量加载, 分步绘制
- Swift: Swift中Selector的变化
- iOS 获取设备型号 ip6更新
- mysql合并binlog
- VBA中数据库导出数据到Excel注意事项
- bzoj1648 / P2853 [USACO06DEC]牛的野餐Cow Picnic
- ZooKeeper与Kafka相关
热门文章
- Android开发中用友盟做分享的一些坑
- 监听指定端口数据交互(HttpListenerContext )
- Index Full Scan vs Index Fast Full Scan-1103
- JavaScript Window - 浏览器对象模型
- (JavaScript实现)页面无操作倒计时退出
- Java线程(学习整理)--4---一个简单的生产者、消费者模型
- Java学习----一个对象怎么调用另一个对象呢?
- 如何:在 StackPanel 和 DockPanel 之间进行选择
- Python Tutorial 学习(三)--An Informal Introduction to Python
- 我学C的那些年[ch01]:浅淡C语言的编译过程