LeetCode-228汇总区间--数组 双指针
作者:互联网
写的有点冗余
class Solution {
public List<String> summaryRanges(int[] nums) {
//关键字:无重复 有序
//
List<String>list=new ArrayList();
int left=0;
int right;
if(nums.length==0){
return list;
}
for(right=0;right<nums.length-1;right++){
if(nums[right]+1!=nums[right+1]){
if(left==right){
list.add(nums[right]+"");
}else{
list.add(nums[left]+"->"+nums[right]);
}
left=right+1;
}
}
if(left==right){
list.add(nums[right]+"");
}else{
list.add(nums[left]+"->"+nums[right]);
}
return list;
}
}
标签:right,nums,--,list,int,add,228,LeetCode,left 来源: https://blog.csdn.net/WA_MC/article/details/120589357