add new solutions
This commit is contained in:
parent
475d438db4
commit
1433bf4850
17 changed files with 394 additions and 0 deletions
29
solutions/24/q2483/solution.go
Normal file
29
solutions/24/q2483/solution.go
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue