Why “Merged Sorted Array" does not let me pass?


  • 0
    N
    class Solution:
        # @param A  a list of integers
        # @param m  an integer, length of A
        # @param B  a list of integers
        # @param n  an integer, length of B
        # @return nothing
        def merge(self, A, m, B, n):
        	i = 0
        	while i < len(A) and len(B) != 0: 
                if B[0] <= A[i]:
                    A.insert(i, B[0])
                    B.pop(0)
                i = i + 1
    
            map(A.append, B)
    
            return A
    

    My code is as above, when I submit my code, it said:

    Submission Result: Wrong Answer

    Input: 	[], [1]
    Output: 	[0]
    Expected: 	[1]
    

    Why? I have tried these parameters in my local machine, it works well.
    My test code is

    A = []    
    B = [1]
    print solution.merge(A, len(A), B, len(B))   # output [1]
    print A                                                        # output [1]

Log in to reply
 

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