We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8e4dbdb commit 17887c3Copy full SHA for 17887c3
Counting Sort/README.markdown
@@ -20,9 +20,9 @@ Count 0 1 1 1 0 0 0 2 1 1 1
20
Here is the code to accomplish this:
21
22
```swift
23
- let maxElement = array.maxElement() ?? 0
24
-
25
- var countArray = [Int](count: Int(maxElement + 1), repeatedValue: 0)
+ let maxElement = array.max() ?? 0
+
+ var countArray = [Int](repeating: 0, count: Int(maxElement + 1))
26
for element in array {
27
countArray[element] += 1
28
}
@@ -62,7 +62,7 @@ Output 1 2 3 7 7 8 9 10
62
Here is the code for this final step:
63
64
65
- var sortedArray = [Int](count: array.count, repeatedValue: 0)
+ var sortedArray = [Int](repeating: 0, count: array.count)
66
67
countArray[element] -= 1
68
sortedArray[countArray[element]] = element
0 commit comments