import java.util.ArrayList; public class Solution { //解题思路:递增的数组,可以用前后双指针 public ArrayList<Integer> FindNumbersWithSum(int [] array,int sum) { ArrayList<Integer> result = new ArrayList<Integer>(); if(array == null || array.length == 0) { return result; } int start = 0; int end = array.length - 1; while(end > start) { if(array[start] + array[end] == sum) { result.add(array[start]); result.add(array[end]); break; } else if(array[start] + array[end] > sum){//大于sum,则后指针左移 end--; } else {//小于sum,则前指针右移 start++; } } return result; } }