1 Star 0 Fork 0

Neo_1001/LeetCode刷题记录

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
LC_88.java 822 Bytes
Copy Edit Raw Blame History
Neo_1001 authored 2024-04-10 22:16 . first commit
package LeetCode;
import java.util.Arrays;
public class LC_88 {
public static void main(String[] args) {
merge(new int[]{0}, 0, new int[]{1}, 1);
}
public static void merge(int[] nums1, int m, int[] nums2, int n) {
int[] res = new int[m + n];
int i = 0;
int j = 0;
int k = 0;
while (i < n && j < m) {
if (nums1[i] <= nums2[j]) {
res[k++] = nums1[i++];
} else res[k++] = nums2[j++];
}
if (j < n) {
while (j < n && k < m + n) {
res[k++] = nums2[j++];
}
} else if (i < m) {
while (i < m && k < m + n) {
res[k++] = nums1[i++];
}
}
nums1 = res;
System.out.println(Arrays.toString(res));
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/neo1001/leet-code-practice-record.git
git@gitee.com:neo1001/leet-code-practice-record.git
neo1001
leet-code-practice-record
LeetCode刷题记录
master

Search