题目意思:num1和num2均为递增数组,对其进行递增排序存到num1中
class Solution {
public:
void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
vector<int> nums3(nums1); //挺好用,vector克隆
int index1=,index2=,index3=;
while(index2<n&&index3<m){
if(nums2[index2]<=nums3[index3]){
nums1[index1++]=nums2[index2++];
}
else{
nums1[index1++]=nums3[index3++];
}
}
while(index2<n){
nums1[index1++]=nums2[index2++];
}
while(index3<m){
nums1[index1++]=nums3[index3++];
}
}
};
时间复杂度:O(n)
运行时间:4ms