Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add swift implementation to lcp problem: No.66 #3998

Merged
merged 1 commit into from
Jan 27, 2025
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