HELP!I want to know why mine is wrong....


  • 0
    F

    public class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
    if (nums1 == null || nums1.length == 0||nums2 == null || nums2.length == 0) return;
    ArrayList result=new ArrayList();
    int i=0,j=0;
    int a=0,b=0;

        while(a+b<nums1.length+nums2.length){
             
            if(nums1[i]<=nums2[j]||b==nums2.length){
            result.add(i+j,nums1[i]);
                a++;
                if(i<nums1.length-1){
                   i++; 
                }
            
        }
        if(nums1[i]>=nums2[j]||a==nums1.length){
            result.add(i+j,nums2[j]);
            b++;
            if(j<nums2.length-1){
                   j++; 
                }
            
        }
          
            
        }
        
        
    }
    

    }


Log in to reply
 

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