Method
merge
(nums1: &mut Vec<i32>, m: i32, nums2: &mut Vec<i32>, n: i32)
Source from the content-addressed store, hash-verified
| 5 | |
| 6 | impl Solution { |
| 7 | pub fn merge(nums1: &mut Vec<i32>, m: i32, nums2: &mut Vec<i32>, n: i32) { |
| 8 | let (m, n) = (m as usize, n as usize); |
| 9 | let mut buffer = Vec::<i32>::with_capacity(m + n); |
| 10 | let (mut i, mut j) = (0, 0); |
| 11 | while i < m || j < n { |
| 12 | if j == n || (i < m && nums1[i] <= nums2[j]) { |
| 13 | buffer.push(nums1[i]); |
| 14 | i += 1; |
| 15 | } else { |
| 16 | buffer.push(nums2[j]); |
| 17 | j += 1; |
| 18 | } |
| 19 | } |
| 20 | *nums1 = buffer; // move into nums1 |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | struct Solution {} |
Callers
nothing calls this directly
Tested by
no test coverage detected