Skip to content

Commit d4798f9

Browse files
committed
GO: 75. Sort Colors
1 parent 955d72c commit d4798f9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

go/75-Sort-Colors.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
func sortColors(nums []int) {
2+
low, mid, hi := 0, 0, len(nums)-1
3+
4+
for low <= hi {
5+
if nums[low] == 2 {
6+
nums[low], nums[hi] = nums[hi], nums[low]
7+
hi--
8+
} else if nums[low] == 0 {
9+
nums[low], nums[mid] = nums[mid], nums[low]
10+
mid++
11+
low++
12+
} else {
13+
low++
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)