Need help clarify the question, what exactly should the size of nums1 need to be?


  • 3
    L

    I couldn't understand the question.
    For example, the following input will return ArrayIndexOutOfBoundsException, what exactly should the size of nums1 should be?

    [1,3,5,7,9]

    5

    [2,4]

    2

    Can you give some examples what the input look like and the output?


  • 5
    R
        nums1.length() >= m+n, m is the initialized elements in nums1 and n is the initialized elements in nums2.
        
        example 1:
        nums1=[1,2,3,4,5,0,0,0,0,0], m=5 ( zeros are default elements in an array)
        nums2=[2,3,4,0,0,0,0], n=3
        nums1.length() = 10 > 8 (which is m+n)
        output: [1,2,2,3,3,4,4,5,0,0]
        
        example 2:
        nums1=[1,2,3,4,5,0,0,0,0,0], m=5
        nums2=[2,3,4,5,6], n=5
        nums1.length() = 10 (which also equals to m+n)
        output: [1,2,2,3,3,4,4,5,5,6]

Log in to reply
 

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