LeetCode88.合并两个有序数组(Java实现)

链接:https://leetcode-cn.com/problems/merge-sorted-array/

class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int index1=m-1;
        int index2=n-1;
        int indexEnd=m+n-1;
        while(index1>=0&&index2>=0){
            if(nums1[index1]>nums2[index2]){
                nums1[indexEnd--]=nums1[index1--];
            }else{
                nums1[indexEnd--]=nums2[index2--];
            }
        }
        if(index2>=0){
            int index=0;
            for(int i=index1+1;i

 

你可能感兴趣的:(LeetCode编程题)