class Solution: # @param A a list of integers # @return nothing, sort in place def sortColors(self, A): n=len(A) p0,p2=0,n-1 i=0 while i<=p2: if A[i]==0:# swap 0 to p0 A[p0],A[i]=A[i],A[p0] p0+=1 i+=1 elif A[i]==2:#swap 2 to p2 A[p2],A[i]=A[i],A[p2] p2-=1 else: i+=1
Sunday, September 7, 2014
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment