public int[][] findContinuousSequence(int target) { // sliding window int i = 1; int j = 2; int sum = 3; List<int[]> res = new ArrayList<>(); // i, When j meets, it is the exit while(i <j) { // when it is less than j, go back and add j to if(sum <target) { j++; sum += j; } else { // when it is equal, save it to the array from ij if(sum == target) { int[] ans = new int[j-i + 1]; for(int k = i; k <= j; k++) { ans[k-i] = k; } res .add(ans); } // When it is greater than or equal to i, first subtract i from i and go back sum -= i; i++; } } return res.toArray(new int[0][]); }
The sword refers to the continuous positive sequence of Offer-61 and s
Guess you like
Origin blog.csdn.net/a792396951/article/details/114366592
Ranking