add new solutions

This commit is contained in:
kanna5 2025-12-25 14:22:40 +09:00
parent 475d438db4
commit 1433bf4850
17 changed files with 394 additions and 0 deletions

View file

@ -0,0 +1,29 @@
package q2483
func bestClosingTime(customers string) int {
numY := 0
for i := range len(customers) {
if customers[i] == 'Y' {
numY++
}
}
minCloseHour := 0
minPenalty := numY
penalty := numY
for i := range len(customers) {
// close at (i + 1)th hour
switch customers[i] {
case 'N':
penalty++
case 'Y':
penalty--
}
if penalty < minPenalty {
minPenalty = penalty
minCloseHour = i + 1
}
}
return minCloseHour
}
var _ = bestClosingTime