class Solution { /** * 往nums1里塞很难受 * @param nums1 * @param m * @param nums2 * @param n */ public void merge(int[] nums1, int m, int[] nums2, int n) { int[] result = new int[m + n]; int i = 0; int j = 0; int p = 0; while (i < m && j < n) { if (nums1[i] <= nums2[j]) { result[p ++] = nums1[i ++]; } else { result[p ++] = nums2[j ++]; } } while (i < m) { result[p ++] = nums1[i ++]; } while (j < n) { result[p ++] = nums2[j ++]; } System.arraycopy(result, 0, nums1, 0, m + n); } }
LeetCode - 88. 合并两个有序数组
猜你喜欢
转载自blog.51cto.com/tianyiya/2172852
今日推荐
周排行