10000 Add 88_Merge_Sorted_Array.java · seanprashad/leetcode-patterns@5529434 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5529434

Browse files
committed
Add 88_Merge_Sorted_Array.java
1 parent 9cb95fa commit 5529434

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

.gitignore

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
.vscode/**
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env
17+
.env.local
18+
.env.development.local
19+
.env.test.local
20+
.env.production.local
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+
26+
__pycache__

Arrays/88_Merge_Sorted_Array.java

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

0 commit comments

Comments
 (0)
0