I implement a bucket-sort algorithm in python, but I got an error-output([1, 0]) for the input [0, 1], I am pretty sure that my code is correct because it works well in my computer, so does someone know how to get rid of it?
yes I did. the test case should be correct.
btw I thought bucket sort was not in-place sort, which was required by the problem?
I got similar problem that could not pass the test case [1, 0] while my code worked well on my computer, it's weird :(
class Solution: # @param A a list of integers # @return nothing, sort in place def sortColors(self, A): if A != None and len(A) > 1: A, one, two = self._sort(A) # one is the place to insert 1, two is the place to insert 2 def _sort(self, A): if len(A) == 1: if A == 0: return A, 1, 1 if A == 1: return A, 0, 1 if A == 2: return A, 0, 0 tmp = A[-1] A, one, two = self._sort(A[:-1]) if tmp == 0: A.insert(0, tmp) return A, one+1, two+1 if tmp == 1: A.insert(one,tmp) return A, one, two+1 if tmp == 2: A.insert(two,tmp) return A, one, two
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.