Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lcp/LCP 66. 最小展台数量/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,29 @@ func minNumBooths(demand []string) (ans int) {
}
```

#### Swift

```swift
class Solution {
func minNumBooths(_ demand: [String]) -> Int {
var maxBooths = [Int](repeating: 0, count: 26)

for day in demand {
var dailyCount = [Int](repeating: 0, count: 26)
for char in day {
let index = Int(char.asciiValue! - Character("a").asciiValue!)
dailyCount[index] += 1
}
for i in 0..<26 {
maxBooths[i] = max(maxBooths[i], dailyCount[i])
}
}

return maxBooths.reduce(0, +)
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
18 changes: 18 additions & 0 deletions lcp/LCP 66. 最小展台数量/Solution.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
func minNumBooths(_ demand: [String]) -> Int {
var maxBooths = [Int](repeating: 0, count: 26)

for day in demand {
var dailyCount = [Int](repeating: 0, count: 26)
for char in day {
let index = Int(char.asciiValue! - Character("a").asciiValue!)
dailyCount[index] += 1
}
for i in 0..<26 {
maxBooths[i] = max(maxBooths[i], dailyCount[i])
}
}

return maxBooths.reduce(0, +)
}
}
Loading