class Solution {
public void merge(int[] nums1, int m, int[] nums2, int n) {
int[] newArray = new int[nums1.length];
int p1 = 0;
int p2 = 0;
int count = 0;
while(p1<m && p2<n){
if(nums1[p1]<nums2[p2]){
newArray[count++] = nums1[p1];
p1++;
}else{
newArray[count++] = nums2[p2];
p2++;
}
}
if(p1==m){
while(p2<n){
newArray[count++] = nums2[p2++];
}
}else{
while(p1<m){
newArray[count++] = nums1[p1++];
}
}
for(int i=0;i<nums1.length;i++){
nums1[i] = newArray[i];
}
}
}
arrays合并两个数组_合并两个有序数组
最新推荐文章于 2024-01-03 10:08:29 发布