Java solution simple


  • 2
    Z
    public class Solution {
        public void merge(int[] nums1, int m, int[] nums2, int n) {
            int i = m+n-1;
            int len1 = m-1;
            int len2 = n-1;
            while(len1>=0 && len2>=0){
                if(nums1[len1]>nums2[len2]){
                    nums1[i] = nums1[len1--];
                }else{
                    nums1[i] = nums2[len2--];
                }
                i--;
            }
            
            while(len1==-1&&len2>=0){
                nums1[len2] = nums2[len2--];
            }
        }
    }

Log in to reply
 

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