继续潜水

导航

 
import java.util.Arrays;

public class sk1 {
    public static void main(String[] args){
         int [][] two = {{1,2,3},{4,10},{2,5,8}};
            int[] result = merge(two);
            for(int i =0; i < result.length; i++){
                System.out.print(result[i]+",");
            }
        }
        /**
        * k-way merge
        */
        public static int[] merge(int[][] input){
            int[] int1d;//1维数组  
            int len = 0;//1维数组的集合长度
            for (int[] element : input) {  
                len += element.length;  
            }  
            int1d = new int[len];  
            int index = 0;  //标记
            for (int [] i : input) {
                for (int  j : i) {
                    int1d[index++] = j; 
                }
            }
            Arrays.sort(int1d); 
            return int1d;
        }
    }

 

posted on 2018-01-26 13:29  继续潜水  阅读(194)  评论(0编辑  收藏  举报