My 7ms C++ solution


  • 2
    L
        int index = m + n - 1;				// 指向A数组的最后
    	int pa = m - 1;
    	int pb = n - 1;
    	while (pa >= 0 || pb >= 0)
    	{
    		if (pa < 0)						// 数组A比较完了
    		{
    			A[index--] = B[pb--];
    			continue;
    		}
    		if (pb < 0)						// 数组B比较完了
    		{
    			A[index--] = A[pa--];
    			continue;
    		}
    
    		if (A[pa] >= B[pb])
    		{
    			A[index--] = A[pa--];
    		}
    		else
    		{
    			A[index--] = B[pb--];
    		}
    	}

  • 0
    R

    中国同学 哈哈
    好不容易碰到一个中国的
    还要打30个字符才行


  • 0
    A
    This post is deleted!

  • 0
    A

    同顶楼主!!评论居然最少要12字符


Log in to reply
 

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