Python in-place

  • 0
      def sortColors(self, nums):
            :type nums: List[int]
            :rtype: void Do not return anything, modify nums in-place instead.
            sorted_pos = -1
            for wanted in [0,1,2]:
                for i in xrange(sorted_pos+1,len(nums)):
                    if nums[i] == wanted:
                        sorted_pos += 1    
                        nums[i] , nums[sorted_pos] = nums[sorted_pos], nums[i]
            print nums

Log in to reply

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