Question about the greater/merger


  • 0
    F

    Many use the greater for comparison as below. if [3, 3, 4] and [3, 3], this generate [3, 3, 4, 3, 3]; however, if [3, 3, 2] and [3, 3], this will not give the correct solution, right? e.g. [3, 3, 2, 3, 3] will be the result. And the true maximum should be [3, 3, 3, 3, 2].

    public boolean greater(int[] nums1, int i, int[] nums2, int j) {
        while (i < nums1.length && j < nums2.length && nums1[i] == nums2[j]) {
            i++;
            j++;
        }
        return j == nums2.length || (i < nums1.length && nums1[i] > nums2[j]);
    }
    

Log in to reply
 

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