public class Solution { public void merge(int A[], int m, int B[], int n) { int k = m+n-1; int aIdx = m-1; int bIdx = n-1; while(aIdx >= 0 && bIdx >=0){ if(A[aIdx] >= B[bIdx]){ A[k] = A[aIdx]; aIdx--; }else{ A[k] = B[bIdx]; bIdx--; } k--; } // 因为A的数组足够大 所以可能aIdx已经遍历到头了 而bInx还没 while(bIdx >= 0){ A[k] = B[bIdx]; bIdx--; k--; } } }
相关文章
- 12-03search-in-rotated-sorted-array-ii
- 12-03LeetCode:21_Merge Two Sorted Lists | 合并两个排序列表 | Easy
- 12-03leetcode@ [289] Game of Life (Array)
- 12-03LeetCode #1636. Sort Array by Increasing Frequency
- 12-03【leetcode_easy_greedy】1005. Maximize Sum Of Array After K Negations
- 12-03【LeetCode】109. Convert Sorted List to Binary Search Tree 解题报告(Python)
- 12-03LeetCode不定时刷题——Convert Sorted Array to Binary Search Tree
- 12-03LeetCode - Count Sorted Vowel Strings
- 12-03[LeetCode] 56. Merge Intervals
- 12-03leetcode56 - Merge Intervals - medium