当前位置: 代码迷 >> 综合 >> Leetcode 1629. Slowest Key
  详细解决方案

Leetcode 1629. Slowest Key

热度:76   发布时间:2023-12-12 21:01:09.0

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Slowest Key

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

  1. https://leetcode.com/problems/slowest-key/