feat: 88_merge_sorted_array
This commit is contained in:
parent
45408b5a46
commit
9acabc6597
20
88_merge_sorted_array/main.cpp
Normal file
20
88_merge_sorted_array/main.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
void merge(vector<int>& nums3, int m, vector<int>& nums2, int n) {
|
||||||
|
vector<int> nums1(nums3);
|
||||||
|
|
||||||
|
for (int i1 = 0, i2 = 0; i1 + i2 < m + n;) {
|
||||||
|
int x1 = i1 < m ? nums1[i1] : INT32_MAX;
|
||||||
|
int x2 = i2 < n ? nums2[i2] : INT32_MAX;
|
||||||
|
|
||||||
|
if (x1 <= x2) {
|
||||||
|
nums3[(i1++) + i2] = x1;
|
||||||
|
} else {
|
||||||
|
nums3[i1 + (i2++)] = x2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user