python solution with Insertion Sort


  • 0
    L
        def sortColors(self, nums):
            """
            :type nums: List[int]
            :rtype: void Do not return anything, modify nums in-place instead.
            """
            for index in range(1,len(nums)):
                currentvalue = nums[index]
                position = index
                
                while position>0 and nums[position-1]>currentvalue:
                    nums[position]=nums[position-1]
                    position = position-1
                    
                nums[position]=currentvalue
    

Log in to reply
 

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