Skip to content

Commit

Permalink
GO: 75. Sort Colors
Browse files Browse the repository at this point in the history
  • Loading branch information
MaratKhakim committed Aug 14, 2022
1 parent 955d72c commit d4798f9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions go/75-Sort-Colors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
func sortColors(nums []int) {
low, mid, hi := 0, 0, len(nums)-1

for low <= hi {
if nums[low] == 2 {
nums[low], nums[hi] = nums[hi], nums[low]
hi--
} else if nums[low] == 0 {
nums[low], nums[mid] = nums[mid], nums[low]
mid++
low++
} else {
low++
}
}
}

0 comments on commit d4798f9

Please sign in to comment.