m+n complexity


  • 0
    P
    class Solution {
        public void merge(int[] nums1, int m, int[] nums2, int n) {
    
            int len = m+n-1;
            int i = m-1;
            int j = n-1;
    
            while(len>=0 && i>-1 && j>-1) {
                if(nums1[i]<=nums2[j]) {
                    nums1[len--] = nums2[j--];
                } else if(nums1[i]>=nums2[j]) {
                    nums1[len--] = nums1[i--];
                }
            }
            while(j>-1) {
                nums1[len--] = nums2[j--];
            }
        }
    }
    

Log in to reply
 

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