标签:res public ted pos while style color nbsp bsp
1 class Solution { 2 public void merge(int[] nums1, int m, int[] nums2, int n) { 3 int[] res = new int[m + n]; 4 int pos = 0; 5 int i = 0, j = 0; 6 while(i < m || j < n) { 7 if(i >= m) { 8 while(j < n) { 9 res[pos] = nums2[j]; 10 pos++; 11 j++; 12 } 13 }else if(j >= n) { 14 while(i < m) { 15 res[pos] = nums1[i]; 16 pos++; 17 i++; 18 } 19 }else { 20 if(nums1[i] < nums2[j]) { 21 res[pos] = nums1[i]; 22 i++; 23 pos++; 24 }else { 25 res[pos] = nums2[j]; 26 j++; 27 pos++; 28 } 29 } 30 } 31 for(i = 0; i < m+n; i++) { 32 nums1[i] = res[i]; 33 } 34 35 } 36 }
标签:res public ted pos while style color nbsp bsp
原文地址:https://www.cnblogs.com/goPanama/p/9655477.html