Skip to content

Commit

Permalink
Create: 0075-sort-colors.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
Ykhan799 authored Feb 4, 2023
1 parent 7bed4f9 commit 02a091a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions swift/0075-sort-colors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Bucket Sort Solution
class Solution {
func sortColors(_ nums: inout [Int]) {
var counts = [0, 0, 0]
for n in nums {
counts[n] += 1
}

var i = 0
for n in 0..<counts.count {
for j in 0..<counts[n] {
nums[i] = n
i += 1
}
}
}
}

0 comments on commit 02a091a

Please sign in to comment.