【LeetCode从零单排】No88.Merge Sorted Array
生活随笔
收集整理的這篇文章主要介紹了
【LeetCode从零单排】No88.Merge Sorted Array
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目
Given two sorted integer arrays A and B, merge B into A as one sorted array.
Note:
You may assume that A has enough space (size that is greater or equal to?m?+?n) to hold additional elements from B. The number of elements initialized in A and B are?m?and?nrespectively.
代碼
public class Solution {public void merge(int A[], int m, int B[], int n) {while (m > 0 && n > 0) {if (A[m-1] > B[n-1]) {A[m+n-1] = A[m-1];m--;} else {A[m+n-1] = B[n-1];n--;}}while (n > 0) {A[n-1] = B[n-1];n--;}} }代碼下載:https://github.com/jimenbian/GarvinLeetCode
/********************************
* 本文來自博客 ?“李博Garvin“
* 轉載請標明出處:http://blog.csdn.net/buptgshengod
******************************************/
總結
以上是生活随笔為你收集整理的【LeetCode从零单排】No88.Merge Sorted Array的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【LeetCode从零单排】No70.C
- 下一篇: 【LeetCode从零单排】No83 R