Skip to content

Commit 4b79939

Browse files
committed
2
1 parent 6651a7b commit 4b79939

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

MergeSortedArray/MergeSortedArray.cpp

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(int A[], int m, int B[], int n) {
4+
// Start typing your C/C++ solution below
5+
// DO NOT write int main() function
6+
7+
int end = m + n - 1;
8+
m -= 1;
9+
n -= 1;
10+
while (m >= 0 && n >= 0) {
11+
if (A[m] > B[n])
12+
A[end--] = A[m--];
13+
else
14+
A[end--] = B[n--];
15+
}
16+
while (m >= 0)
17+
A[end--] = A[m--];
18+
while (n >= 0)
19+
A[end--] = B[n--];
20+
}
21+
};

0 commit comments

Comments
 (0)