import java.util.ArrayList;
public class Solution {
    public ArrayList<Integer> FindNumbersWithSum(int [] array,int sum) {
        ArrayList<Integer> res = new ArrayList<>();
        // 一些特殊情况的处理
        if (array.length < 2) {
            return res;
        }
        int[] map = new int[array[array.length - 1] + 1];
        for (int i = 0; i < array.length; i++) {
            int tmp = sum - array[i];
            if (tmp >= 1 && tmp <= array[array.length - 1] && map[tmp] != 0) {
                res.add(array[i]);
                res.add(tmp);
                break;
            }
            map[array[i]] = 1;
        }
        return res;
    }
}