Leetcode 1629. Slowest Key
Posted SnailTyan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 1629. Slowest Key相关的知识,希望对你有一定的参考价值。
文章作者: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 = temp
elif temp == time and keysPressed[i] > key:
key = keysPressed[i]
return key
Reference
以上是关于Leetcode 1629. Slowest Key的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode 1629 按键持续时间最长的按键[遍历] HERODING的LeetCode之路