Merge Sorted Array

Given two sorted integer arraysnums1_and_nums2, merge_nums2_into_nums1_as one sorted array.

Note:

  • The number of elements initialized in

    nums1

    and

    nums2

    are

    m

    and

    n

    respectively.

  • You may assume that

    nums1

    has enough space (size that is greater or equal to

    m

    +

    n

    ) to hold additional elements from

    nums2

    .

Example:

分析

尾部开始填充

3个while,开始while i>=0 and j>=0: 然后while i>=0:和while j>=0:

java 代码简单,m到头证明结束,所以只需要判断N。

Last updated

Was this helpful?