mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
init
This commit is contained in:
28
23/08/Q88.cpp
Normal file
28
23/08/Q88.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by 李洋 on 2023/8/13.
|
||||
//
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
class Q88 {
|
||||
public:
|
||||
void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
|
||||
int p1 = 0, p2 = 0;
|
||||
int sorted[m + n];
|
||||
int cur;
|
||||
while (p1 < m || p2 < n) {
|
||||
if (p1 == m) {
|
||||
cur = nums2[p2++];
|
||||
} else if (p2 == n) {
|
||||
cur = nums1[p1++];
|
||||
} else if (nums1[p1] < nums2[p2]) {
|
||||
cur = nums1[p1++];
|
||||
} else {
|
||||
cur = nums2[p2++];
|
||||
}
|
||||
sorted[p1 + p2 - 1] = cur;
|
||||
}
|
||||
for (int i = 0; i != m + n; ++i) {
|
||||
nums1[i] = sorted[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user