1 import java.util.ArrayList;
2 public class Solution {
3 public ArrayList<Integer> FindNumbersWithSum(int [] array,int sum) {
4 ArrayList<Integer> result = new ArrayList<Integer>();
5 if(array==null||array.length<2)
6 return result;
7 int plow=0,phigh=array.length-1;
8 while(phigh>plow){
9 int cur=array[phigh]+array[plow];
10 if(cur==sum){
11 result.add(array[plow]);
12 result.add(array[phigh]);
13 return result;
14 }else if(cur<sum){
15 plow++;
16 }else{
17 phigh--;
18 }
19 }
20 return result;
21 }
22 }