*Java* one-pass, 4 lines, 0ms


  • 10
    E
    public void merge(int[] nums1, int m, int[] nums2, int n) {
    	int p = m+n, p1 = m-1, p2 = n-1;
    	while(--p>=0) {
    		if(p1<0 || (p2>=0 && nums1[p1]<nums2[p2])) nums1[p] = nums2[p2--];
    		else nums1[p] = nums1[p1--];
    	}
    }

Log in to reply
 

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