Leetcode Note: Go - Slowest Key
Slowest Key - LeetCode
https://leetcode.com/problems/slowest-key/
- Go 言語で取り組んだメモ
回答
Golang solution - Slowest Key - LeetCode
https://leetcode.com/problems/slowest-key/solutions/1236566/golang-solution/
func slowestKey(releaseTimes []int, keysPressed string) byte {
max := releaseTimes[0]
letter := keysPressed[0]
for i := 1; i < len(releaseTimes); i++ {
difference := releaseTimes[i] - releaseTimes[i-1]
if difference > max {
max = difference
letter = keysPressed[i]
} else if difference == max && keysPressed[i] > letter {
max = difference
letter = keysPressed[i]
}
}
return letter
}