What's wrong with this code ?


  • 0
    T
        class Solution {
    public:
        void merge(int A[], int m, int B[], int n) {
    		int alen = m;
    		int blen = 0;
    		int amax = A[m-1];
            for (int i = 0;i < n; ++i)
    		{
    			if (B[i] < amax)
    			{
    				insert(A,alen,B[i]);
    				++alen;++blen;
    			}
    			else
    				break;
    		}
    		/*for (int i = blen; i < n; ++i)
    			A[alen++] = B[i];*/
    		memcpy(A+alen,B+blen,(n-blen)*sizeof(int));
        }
    	void insert(int a[],int len,int value)
    	{
    		for (int i = len;i >=0; --i)
    		{
    			if (a[i-1] > value)
    				a[i] = a[i-1];
    			else
    			{
    				a[i] = value;
    				break;
    			}
    		}
    	}
    };
    

    this code in my plateform is perform right,but in oj is always wrong.


Log in to reply
 

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