1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00

go: add «75. Sort Colors»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-06-12 17:33:21 +02:00
parent 1e48c99bfb
commit fbc9fdb7ad
Signed by: mfocko
GPG key ID: 7C47D46246790496

17
go/sort-colors.go Normal file
View file

@ -0,0 +1,17 @@
package sort_colors
func sortColors(nums []int) {
l, r := 0, len(nums)-1
for i, _ := range nums {
for l <= i && i <= r && nums[i] != 1 {
if nums[i] == 0 {
nums[i], nums[l] = nums[l], nums[i]
l++
} else if nums[i] == 2 {
nums[i], nums[r] = nums[r], nums[i]
r--
}
}
}
}