码迷,mamicode.com
首页 > 编程语言 > 详细

一个排好序的数组,找出两数之和为m的所有组合

时间:2017-12-14 17:56:38      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:++   out   log   print   int start   post   class   stat   div   

    public  static void getGroup(int sum, int arr[]){
        if(arr.length<=0) {
            System.out.println("数组为空");
            return;
        }
        int start = 0;
        int end =arr.length-1;
        while (start <end){
            if(arr[start]+arr[end]== sum){
                System.out.println("符合要求"+arr[start]+","+arr[end]);
                 start++;
                 end--;
            }else if(arr[start]+arr[end] > sum) {
                end--;
            }else if(arr[start]+arr[end] < sum){
                start++;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr ={-4,2,5,6,8,9,9,10,11,19};
        getGroup(15,arr);
    }

一个排好序的数组,找出两数之和为m的所有组合

标签:++   out   log   print   int start   post   class   stat   div   

原文地址:http://www.cnblogs.com/xiaoshanqiu/p/8038696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!