文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
**解析:**Version 1,遍历每个字符,计算其时间间隔,如果比之前的大,则更新时间间隔及字符,如果相等,则比较字符大小,判断是否更新字符。
- Version 1
class Solution:def slowestKey(self, releaseTimes: List[int], keysPressed: str) -> str:n = len(keysPressed)key = keysPressed[0]time = releaseTimes[0]for i in range(1, n):temp = releaseTimes[i] - releaseTimes[i-1]if temp > time:key = keysPressed[i]time = tempelif temp == time and keysPressed[i] > key:key = keysPressed[i]return key
Reference
- https://leetcode.com/problems/slowest-key/