注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本帖最后由 guwwu 于 2026-8-11 22:07 编辑
Q: Given two unsorted integer arrays a and b, where a has enough placeholder positions at the end to hold all elements of b, merge b into a and sort the final array in ascending order.
public void merge(int[] a, int[] b)
a = [5, 1, 3, 0, 0, 0]
b = [6, 2, 4]
result:
a = [1, 2, 3, 4, 5, 6]
public void merge(int[] a, int[] b) {
// Copy b into the placeholder positions
int m = a.length - b.length;
for (int i = 0; i < b.length; i++) { ..
a[m + i] = b[i];
}
// Sort the entire array
Arrays.sort(a);.google и
} |