Skip to content

Instantly share code, notes, and snippets.

@Irene-123
Created June 21, 2020 07:13
Show Gist options
  • Save Irene-123/7b3c4853e78378c3f2e23c111f300931 to your computer and use it in GitHub Desktop.
Save Irene-123/7b3c4853e78378c3f2e23c111f300931 to your computer and use it in GitHub Desktop.
Leetcode solution-Sort Colors .Dutch National Flag problem
```python3
#https://en.wikipedia.org/wiki/Dutch_national_flag_problem
#https://leetcode.com/problems/sort-colors/
def sortColors(self, nums):
red, white, blue = 0, 0, len(nums)-1
while white <= blue:
if nums[white] == 0:
nums[red], nums[white] = nums[white], nums[red]
white += 1
red += 1
elif nums[white] == 1:
white += 1
else:
nums[white], nums[blue] = nums[blue], nums[white]
blue -= 1
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment