Skip to content

Commit a9900f1

Browse files
author
cpppy
authored
Create 88_Merge_Sorted_Array.cc
1 parent f74a5fa commit a9900f1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

88_Merge_Sorted_Array.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
4+
if(n==0) return;
5+
int i=m-1;
6+
int j=n-1;
7+
int k=m+n-1;
8+
while(i>=0 && j>=0){
9+
if(nums1[i]>nums2[j]){
10+
nums1[k--]=nums1[i--];
11+
}
12+
else{
13+
nums1[k--]=nums2[j--];
14+
}
15+
}
16+
while(j>=0){
17+
nums1[k--]=nums2[j--];
18+
}
19+
}
20+
21+
};

0 commit comments

Comments
 (0)