File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,29 @@ func minNumBooths(demand []string) (ans int) {
151151}
152152```
153153
154+ #### Swift
155+
156+ ``` swift
157+ class Solution {
158+ func minNumBooths (_ demand : [String ]) -> Int {
159+ var maxBooths = [Int ](repeating : 0 , count : 26 )
160+
161+ for day in demand {
162+ var dailyCount = [Int ](repeating : 0 , count : 26 )
163+ for char in day {
164+ let index = Int (char.asciiValue ! - Character (" a" ).asciiValue ! )
165+ dailyCount[index] += 1
166+ }
167+ for i in 0 ..< 26 {
168+ maxBooths[i] = max (maxBooths[i], dailyCount[i])
169+ }
170+ }
171+
172+ return maxBooths.reduce (0 , + )
173+ }
174+ }
175+ ```
176+
154177<!-- tabs: end -->
155178
156179<!-- solution: end -->
Original file line number Diff line number Diff line change 1+ class Solution {
2+ func minNumBooths( _ demand: [ String ] ) -> Int {
3+ var maxBooths = [ Int] ( repeating: 0 , count: 26 )
4+
5+ for day in demand {
6+ var dailyCount = [ Int] ( repeating: 0 , count: 26 )
7+ for char in day {
8+ let index = Int ( char. asciiValue! - Character( " a " ) . asciiValue!)
9+ dailyCount [ index] += 1
10+ }
11+ for i in 0 ..< 26 {
12+ maxBooths [ i] = max ( maxBooths [ i] , dailyCount [ i] )
13+ }
14+ }
15+
16+ return maxBooths. reduce ( 0 , + )
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments