Skip to content

Commit 1be982d

Browse files
authored
Merge pull request neetcode-gh#2207 from Ykhan799/main
Create: 0075-sort-colors.swift
2 parents 7bed4f9 + 02a091a commit 1be982d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

swift/0075-sort-colors.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Bucket Sort Solution
2+
class Solution {
3+
func sortColors(_ nums: inout [Int]) {
4+
var counts = [0, 0, 0]
5+
for n in nums {
6+
counts[n] += 1
7+
}
8+
9+
var i = 0
10+
for n in 0..<counts.count {
11+
for j in 0..<counts[n] {
12+
nums[i] = n
13+
i += 1
14+
}
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)