일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 프로그래머스
- 715. Range Module
- 컴퓨터의 구조
- Generator
- Python
- 43. Multiply Strings
- Convert Sorted List to Binary Search Tree
- LeetCode
- Decorator
- 30. Substring with Concatenation of All Words
- Regular Expression
- Protocol
- 시바견
- kaggle
- iterator
- concurrency
- 밴픽
- DWG
- Python Implementation
- t1
- 파이썬
- Class
- shiba
- 109. Convert Sorted List to Binary Search Tree
- 운영체제
- Substring with Concatenation of All Words
- attribute
- 315. Count of Smaller Numbers After Self
- Python Code
- data science
Archives
- Today
- Total
목록Top K Frequent Elements (1)
Scribbling
LeetCode: 347. Top K Frequent Elements
빈도를 기억하기 위한 hashmap을 사용하자. from collections import defaultdict class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: dic = defaultdict(int) for num in nums: dic[num] += 1 temp = [] for key, val in dic.items(): temp.append([val, key]) temp.sort(key=lambda x: -x[0]) temp = temp[:k] return [t[1] for t in temp]
Computer Science/Coding Test
2021. 11. 15. 19:55