leetcode:按键持续时间最长的键
作者:互联网
代码:
class Solution:
def slowestKey(self, releaseTimes: List[int], keysPressed: str) -> str:
res = ''
lastTime = 0
maxDuration = -1
for i in range(len(releaseTimes)):
duration = releaseTimes[i] - lastTime
if duration > maxDuration:
maxDuration = duration
res = keysPressed[i]
elif duration == maxDuration and res < keysPressed[i]:
res = keysPressed[i]
lastTime = releaseTimes[i]
return res
标签:releaseTimes,持续时间,res,maxDuration,keysPressed,按键,duration,lastTime,leetcode 来源: https://blog.csdn.net/weixin_40986490/article/details/122389799