Note: original solution with array shifting
(nums1 []int, m int, nums2 []int, n int)
| 54 | |
| 55 | // Note: original solution with array shifting |
| 56 | func merge0(nums1 []int, m int, nums2 []int, n int) { |
| 57 | slot := 0 |
| 58 | |
| 59 | // for each in nums2, insert into nums1 |
| 60 | for i := 0; i < n; i++ { |
| 61 | |
| 62 | // find the slot to insert nums2[i] into |
| 63 | for slot < m+i && nums1[slot] <= nums2[i] { |
| 64 | slot++ |
| 65 | } |
| 66 | |
| 67 | // count how many shifts are needed |
| 68 | shiftCnt := m - slot + 1 + i |
| 69 | |
| 70 | // shift over each number to insert nums2[i] |
| 71 | for s := 0; s < shiftCnt; s++ { |
| 72 | hold := nums2[i] |
| 73 | nums2[i] = nums1[slot+s] |
| 74 | nums1[slot+s] = hold |
| 75 | } |
| 76 | } |
| 77 | } |
nothing calls this directly
no outgoing calls
no test coverage detected