Skip to content

Commit dda41ac

Browse files
committed
Create sort-colors.go
1 parent 32e863d commit dda41ac

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

sort-colors.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//https://leetcode.com/problems/sort-colors/
2+
3+
package leetcode_solutions_golang
4+
5+
func sortColors(nums []int) {
6+
count := [3]int{0, 0, 0}
7+
for i := 0; i < len(nums); i++ {
8+
count[nums[i]]++
9+
}
10+
index := 0
11+
for i := 0; i < 3; i++ {
12+
for j := 0; j < count[i]; j++ {
13+
nums[index] = i
14+
index++
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)