Can anyone tell me why is this wrong?


  • 0
    J
    class Solution:
        # @param {integer[]} nums
        # @return {void} Do not return anything, modify nums in-place instead.
        def sortColors(self, nums):
            num0 = nums.count(0)
            num1 = nums.count(1)
            num2 = nums.count(2)
            nums=[]
            while num0!=0:
                nums.append(0)
                num0-=1
            while num1!=0:
                nums.append(1)
                num1-=1
            while num2!=0:
                nums.append(2)
                num2-=1
    

    17 / 86 test cases passed.
    Status: Wrong Answer

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

    It works on Python IDE but it doesn't work here...I wonder why


  • -1

    You're supposed to modify the existing list, not build a new one (that you don't even give to the caller).


  • 0

    Wondering what kind of idiot downvoted this, and why...


Log in to reply
 

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