和为 S 的两个数字

public ArrayList<Integer> FindNumbersWithSum(int [] array, int sum) {
    ArrayList<Integer> res = new ArrayList<>();
    int start=0;
    int end =array.length-1;
    while(start<end){
        if(array[start]+array[end]==sum){ //TODO:最先找到的这两个数的乘积最小的。
            res.addAll(Arrays.asList(array[start],array[end]));
            return res;
        }else if(array[start]+array[end]<sum){
            start++;
        }else {
            end--;
        }
    }
    return res;
}

https://www.mianshi.onlinehttps://www.i9code.cn

本文由博客一文多发平台 OpenWrite 发布!

逃跑的眼镜_bvbEK5
7 声望0 粉丝