12345678910111213141516171819202122 |
- package main
- // ?? check the best solution the next time
- func sortColors(nums []int) {
- mCnt := [3]int{}
- for _, v := range nums {
- mCnt[v]++
- }
- for idx, color := 0, 0; color < 3; color++ {
- cnt := mCnt[color]
- for i := 0; i < cnt; idx, i = idx+1, i+1 {
- nums[idx] = color
- }
- }
- }
- /* func main() {
- c1 := []int{0, 1, 1, 2, 0, 0, 1, 2, 1}
- sortColors(c1)
- fmt.Println(c1)
- sortColors([]int{})
- } */
|