My C++ solution(7 ms)


  • 0
    B
    class Solution {
    public:
        void merge(int A[], int m, int B[], int n) {
            int i = m - 1;
            int j = n - 1;
            while (i >= 0 || j >= 0) {
                if (i >= 0 && (A[i] >= B[j] || j < 0)) A[i + j + 1] = A[i--];
                else A[i + j + 1] = B[j--];
            }
        }
    };

  • 0
    Y

    Short and clear code!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.