Java: Interleaving multiple arrays into a single array

后端 未结 5 592
误落风尘
误落风尘 2020-12-19 06:13

I found similar question about interleaving two arraylists into one, but its in PHP. I was asked this question in interview as well but could\'nt solve it, came back to SO t

5条回答
  •  醉话见心
    2020-12-19 06:27

    For simplicity, assume that the arrays are the same length, and are int arrays.

    int[] merge(int[] a, int[] b)
    {
        assert (a.length == b.length);
    
        int[] result = new int[a.length + b.length];
    
        for (int i=0; i

提交回复
热议问题