freedom.9
Senior Member
Q3 giải trong vòng 5 ph cmnr mà làm cái q2 tới cuối giờ mới ra. Trash quá
Câu 1 thì đọc lộn đề, cứ tưởng chỉ có 1 kí tự xuất hiện 2 lần. Bad contest ever
Câu 4 thì xài cái sortedlist xong luôn rồi.
Câu 1 thì đọc lộn đề, cứ tưởng chỉ có 1 kí tự xuất hiện 2 lần. Bad contest ever
Câu 4 thì xài cái sortedlist xong luôn rồi.
Python:
class Solution:
def mostFrequentIDs(self, nums: List[int], freq: List[int]) -> List[int]:
frequency = defaultdict(int)
maxHeap = []
ans = []
for i in range(len(nums)):
frequency[nums[i]] += freq[i]
heapq.heappush(maxHeap, (-frequency[nums[i]], nums[i]))
while maxHeap[0][0]*-1 != frequency[maxHeap[0][1]]:
heapq.heappop(maxHeap)
ans.append(maxHeap[0][0]*-1)
return ans