Simple java solution(3 lines),0ms


  • -1
    H
    public class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int l = m+n; int i = l-1; m--;  n--;
        while(m >= 0 && n >= 0) nums1[i--] = nums1[m] > nums2[n]? nums1[m--]: nums2[n--];   //当nums1和nums2都有数据时
        while( n>=0)nums1[i--] = nums2[n--];          //当nums1处理完,还有剩余nums2情况
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.