lc-go/solutions/24/q2483/solution.go
2025-12-28 12:54:21 +09:00

29 lines
475 B
Go

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