File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ Count 0 1 1 1 0 0 0 2 1 1 1
20
20
Here is the code to accomplish this:
21
21
22
22
``` swift
23
- let maxElement = array.maxElement () ?? 0
24
-
25
- var countArray = [Int ](count : Int (maxElement + 1 ), repeatedValue : 0 )
23
+ let maxElement = array.max () ?? 0
24
+
25
+ var countArray = [Int ](repeating : 0 , count : Int (maxElement + 1 ))
26
26
for element in array {
27
27
countArray[element] += 1
28
28
}
@@ -62,7 +62,7 @@ Output 1 2 3 7 7 8 9 10
62
62
Here is the code for this final step:
63
63
64
64
``` swift
65
- var sortedArray = [Int ](count : array. count , repeatedValue : 0 )
65
+ var sortedArray = [Int ](repeating : 0 , count : array. count )
66
66
for element in array {
67
67
countArray[element] -= 1
68
68
sortedArray[countArray[element]] = element
You can’t perform that action at this time.
0 commit comments