# 剑指offer40/41-和为S的连续正数序列/和为S的两个数字

left最多能到num/2的位置，right最多能到小于num的位置。

import java.util.*;
public class Solution {
public ArrayList<ArrayList<Integer> > FindContinuousSequence(int sum) {
ArrayList<ArrayList<Integer>> result = new ArrayList<>();
if(sum<3){
return result;
}
int left = 1;
int right = 2;
int curSum = left+right;
while(left<right && right<sum){
while(curSum>sum && left<sum/2){
curSum -= left;
left++;
}
if(curSum == sum){
}
right++;
curSum+=right;
}
return result;
}

public ArrayList<Integer> getSequence(int small , int big){
ArrayList<Integer> result = new ArrayList<>();
for(int i=small;i<=big;i++){
}
return result;
}
}


import java.util.ArrayList;
public class Solution {
public ArrayList<Integer> FindNumbersWithSum(int [] array,int sum) {
ArrayList<Integer> result = new ArrayList<>();
if(array==null || array.length<=1){
return result;
}

int smallIndex = 0;
int largeIndex = array.length-1;
while(smallIndex<largeIndex){
if((array[smallIndex]+array[largeIndex])==sum){
//最外层的就是乘积最小的
break;
}
else if((array[smallIndex]+array[largeIndex])<sum){
smallIndex++;
}else{
largeIndex--;
}
}
return result;
}
}


©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客