Given arr1 & arr2, that have been sorted in descending order, output an array which appends values from both arr1 and arr2 in descending order

后端 未结 2 1768
北恋
北恋 2021-01-28 14:05
public int[] join(int[] arr1,int[] arr2){

    int[] joinArr=new int[arr1.length + arr2.length];
    int j=0,k=0;
    for(int i=0;i

        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-28 14:34

    You have 4 possible outcomes. In the last two outcomes, you increment the index when you take a value from arr1[j] or arr2[k]

    You have to do the same for all outcomes, otherwise you just the value you were up to repeatedly.

    BTW I suggest you

    • use the code formatter in your IDE to make your code more readable
    • use the debugger in your IDE to step through the code so you undersand what it is doing.

提交回复
热议问题