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;
}
}

最新文章

  1. Hiberbate
  2. git merge git pull时候遇到冲突解决办法git stash
  3. Windows Phone8.1 SDK中的新控件
  4. document.execCommand()命令小计
  5. Joson的简单用法
  6. 【Stage3D学习笔记续】山寨Starling(十一):Touch事件体系
  7. 注册表被篡改,请重新安装应用程序 acdphotoEdit
  8. jquery之属性操作
  9. JavaScript数组去重方法及测试结果
  10. 关于HashSet集合add元素
  11. bounding box的简单理解
  12. Codeforces 746F Music in Car
  13. [C#]RichTextBox实现拖放
  14. 背水一战 Windows 10 (57) - 控件(集合类): ListViewBase - 增量加载, 分步绘制
  15. Swift: Swift中Selector的变化
  16. iOS 获取设备型号 ip6更新
  17. mysql合并binlog
  18. VBA中数据库导出数据到Excel注意事项
  19. bzoj1648 / P2853 [USACO06DEC]牛的野餐Cow Picnic
  20. ZooKeeper与Kafka相关

热门文章

  1. Android开发中用友盟做分享的一些坑
  2. 监听指定端口数据交互(HttpListenerContext )
  3. Index Full Scan vs Index Fast Full Scan-1103
  4. JavaScript Window - 浏览器对象模型
  5. (JavaScript实现)页面无操作倒计时退出
  6. Java线程(学习整理)--4---一个简单的生产者、消费者模型
  7. Java学习----一个对象怎么调用另一个对象呢?
  8. 如何:在 StackPanel 和 DockPanel 之间进行选择
  9. Python Tutorial 学习(三)--An Informal Introduction to Python
  10. 我学C的那些年[ch01]:浅淡C语言的编译过程