//special test case: //int[]nums1= {2,5,6,4,4,0}; //int []nums2 = {7,3,8,0,6,5,7,6,2}; public boolean greater(int[]nums1,int start1,int[]nums2,int start2){ int m = nums1.length,n = nums2.length; while(start1<m && start2<n){ if(nums1[start1]>nums2[start2]) return true; else if(nums1[start1]<nums2[start2]) return false; else{ start1++; start2++; } } return start1!=m; } public int []getMaxi(int[]nums1,int[]nums2){ int m= nums1.length,n=nums2.length; int k = m+n; int []res=new int[k]; int ind =0,start1=0,start2=0; while(ind<k){ res[ind++]=greater(nums1,start1,nums2,start2)?nums1[start1++]:nums2[start2++]; } return res; }
|