leetcode 88. Merge Sorted Array
本帖最后由 Seawolf 于 2019-9-2 07:01 编辑Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
Note:
The number of elements initialized in nums1 and nums2 are m and n respectively.
You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.
Example:
Input:
nums1 = , m = 3
nums2 = , n = 3
Output:
class Solution {
public void merge(int[] nums1, int m, int[] nums2, int n) {
if(n == 0) return;
if(m == 0){
for(int i = 0; i< n; i++){
nums1 = nums2;
}
}
int count1 = 0, count2= 0, count3= 0;
int[] arr = new int;
while(count1 != (m+n)){
if(count3 < n && (count2 == m || nums1 >= nums2)){
arr = nums2;
}
else if(count2 < m && (count3 == n || nums1 < nums2)){
arr = nums1;
}
}
for(int i = 0; i< arr.length; i++){
nums1 = arr;
}
}
}
页:
[1]