Skip to content

Commit ef57b68

Browse files
committed
add 088
1 parent 719b39e commit ef57b68

File tree

6 files changed

+231
-0
lines changed

6 files changed

+231
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ Idx | Date | Question | Python| Java | Domain | Tag | Difficulty | Remark
4141
035|20200406|[95. Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii/)|[095p](https://github.com/shishishu/leetcode-python-java/blob/master/ipynb_files/095_Unique_Binary_Search_Trees_II.ipynb)|[095j](https://github.com/shishishu/leetcode-python-java/blob/master/java_codes/095/Solution.java)|BST|DP|Medium
4242
036|20200419|[912. Sort an Array](https://leetcode.com/problems/sort-an-array/)|[912p](https://github.com/shishishu/leetcode-python-java/blob/master/ipynb_files/912_Sort_an_Array.ipynb)|[912j](https://github.com/shishishu/leetcode-python-java/blob/master/java_codes/912/Solution.java)|List|Sort|Medium
4343
037|20200419|[540. Single Element in a Sorted Array](https://leetcode.com/problems/single-element-in-a-sorted-array/)|[540p](https://github.com/shishishu/leetcode-python-java/blob/master/ipynb_files/540_Single_Element_in_a_Sorted_Array.ipynb)|[540j](https://github.com/shishishu/leetcode-python-java/blob/master/java_codes/540/Solution.java)|List|Search|Medium
44+
038|20200419|[88. Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/)|[088p](https://github.com/shishishu/leetcode-python-java/blob/master/ipynb_files/088_Merge_Sorted_Array.ipynb)|[088j](https://github.com/shishishu/leetcode-python-java/blob/master/java_codes/088/Solution.java)|List| |Easy
4445

images/088_Q.PNG

51.8 KB
Loading

images/088_S1.PNG

23.3 KB
Loading

ipynb_files/088_Merge_Sorted_Array.ipynb

Lines changed: 200 additions & 0 deletions
Large diffs are not rendered by default.

java_codes/088/Solution.java

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

java_codes/java_codes.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<sourceFolder url="file://$MODULE_DIR$/095" isTestSource="false" />
4242
<sourceFolder url="file://$MODULE_DIR$/912" isTestSource="false" />
4343
<sourceFolder url="file://$MODULE_DIR$/540" isTestSource="false" />
44+
<sourceFolder url="file://$MODULE_DIR$/088" isTestSource="false" />
4445
</content>
4546
<orderEntry type="inheritedJdk" />
4647
<orderEntry type="sourceFolder" forTests="false" />

0 commit comments

Comments
 (0)