1. 程式人生 > >LintCode 64---合並排序數組

LintCode 64---合並排序數組

code color lin 冒泡 並排 solution div merge 合並

public class Solution {
    /*
     * @param A: sorted integer array A which has m elements, but size of A is m+n
     * @param m: An integer
     * @param B: sorted integer array B which has n elements
     * @param n: An integer
     * @return: nothing
     */
    public void mergeSortedArray(int
[] A, int m, int[] B, int n) { for (int i = m; i < m+n; i++) { A[i] = B[i-m]; } //冒泡排序 // for (int i = 0; i < m+n; i++) { // for (int j = i; j < m+n; j++) { // int t = 0; // if(A[i] > A[j]) { // t = A[i];
// A[i] = A[j]; // A[j] = t; // } // } // // } Arrays.sort(A); } }

LintCode 64---合並排序數組