标签:imp util seq 子序列 i++ 指针 for array else
import java.util.ArrayList; public class Solution { public ArrayList<ArrayList<Integer> > FindContinuousSequence(int sum) { ArrayList<ArrayList<Integer>> res=new ArrayList<ArrayList<Integer>> (); if(sum==0)return res; int left=1; int right=2; while(left<right){ int cur=(left+right)*(right-left+1)/2; if(cur==sum){ ArrayList<Integer> l=new ArrayList<>(); for(int i=left;i<=right;i++){ l.add(i); } res.add(l); left++; }else if(cur>sum){ left++; }else{ right++; } } return res; } }
标签:imp util seq 子序列 i++ 指针 for array else
原文地址:https://www.cnblogs.com/NeverGiveUp0/p/11442860.html