Most Frequent Number Following Key In an Array LeetCode solution in Python

1
# Runtime: 90 ms (Top 49.1%) | Memory: 16.67 MB (Top 9.2%)
2

3

4
class Solution:
5
def mostFrequent(self, nums: List[int], key: int) -> int:
6
l = [t for k, t in zip(nums, nums[1:]) if k == key]
7
return max(set(l), key=l.count)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0