MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/easy/_0088/Solution.java:13–35  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/06/01 desc :

Source from the content-addressed store, hash-verified

11 * </pre>
12 */
13public class Solution {
14 public void merge(int[] nums1, int m, int[] nums2, int n) {
15 int p = m-- + n-- - 1;
16 while (m >= 0 && n >= 0)
17 nums1[p--] = nums1[m] > nums2[n] ? nums1[m--] : nums2[n--];
18 while (n >= 0)
19 nums1[p--] = nums2[n--];
20 }
21
22 public static void main(String[] args) {
23 Solution solution = new Solution();
24 int[] nums1 = new int[10];
25 for (int i = 0; i < 5; ++i) {
26 nums1[i] = 2 * i;
27 }
28 int[] nums2 = new int[5];
29 for (int i = 0; i < 5; ++i) {
30 nums2[i] = 2 * i + 1;
31 }
32 solution.merge(nums1, 5, nums2, 5);
33 System.out.println(Arrays.toString(nums1));
34 }
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected