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
2020Here is the code to accomplish this:
2121
2222``` 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 ))
2626 for element in array {
2727 countArray[element] += 1
2828 }
@@ -62,7 +62,7 @@ Output 1 2 3 7 7 8 9 10
6262Here is the code for this final step:
6363
6464``` swift
65- var sortedArray = [Int ](count : array. count , repeatedValue : 0 )
65+ var sortedArray = [Int ](repeating : 0 , count : array. count )
6666 for element in array {
6767 countArray[element] -= 1
6868 sortedArray[countArray[element]] = element
You can’t perform that action at this time.
0 commit comments