-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (36 loc) · 806 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/
package main
import "fmt"
func maximumTime(time string) string {
newSlice := []byte(time)
if newSlice[0] == '?' && newSlice[1] == '?' && newSlice[3] == '?' && newSlice[4] == '?' {
return "23:59"
}
if newSlice[0] == '?' {
if newSlice[1] >= '4' && newSlice[1] <= '9' {
newSlice[0] = '1'
} else {
newSlice[0] = '2'
}
}
if newSlice[1] == '?' {
if newSlice[0] == '2' {
newSlice[1] = '3'
} else {
newSlice[1] = '9'
}
}
if newSlice[3] == '?' {
newSlice[3] = '5'
}
if newSlice[4] == '?' {
newSlice[4] = '9'
}
return string(newSlice)
}
func main() {
fmt.Println(maximumTime("??:??"))
fmt.Println(maximumTime("2?:?0"))
fmt.Println(maximumTime("??:?9"))
fmt.Println(maximumTime("??:3?"))
}