I am working on the sort colors question, which is basically sorting the integer array with only 3 values: 0, 1 and 2. The following code got me "Wrong Answer". However, I did got right answer when I tested it in my python environment.
Here are the error message and my code. Hope somebody can help me out. thanks.
Error Message: Wrong Answer
Correct output: [0,1]
Note: When I input [1,0] in my code, I did get the right output of [0,1]. I do not know why the leetcode get the wrong answer??
My python code.
# @param A a list of integers
# @return nothing, sort in place
def sortColors(self, A):
snum = 
zeroR = 0
for item in A: if (item<1): snum= [item] + snum zeroR += 1 elif (item>1): snum= snum + [item] else: snum.insert(zeroR,item) return(snum)