05-1 : Top K Frequent Elements
Overview
I walk you through how to solve Leetcode problem 347. Top K Frequent Elements.
Approach 1: Count HashMap
def topKFrequent(nums, k):
count = {}
res = []
for n in nums:
count[n] = count.get(n, 0) + 1
for _ in range(k):
...
rohanmorar.hashnode.dev2 min read