일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Substring with Concatenation of All Words
- Convert Sorted List to Binary Search Tree
- Python Implementation
- Class
- Protocol
- Regular Expression
- attribute
- Decorator
- Python
- 43. Multiply Strings
- 프로그래머스
- 밴픽
- 컴퓨터의 구조
- data science
- shiba
- Python Code
- kaggle
- 운영체제
- 시바견
- concurrency
- 715. Range Module
- 파이썬
- DWG
- Generator
- 109. Convert Sorted List to Binary Search Tree
- 30. Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- iterator
- t1
- LeetCode
Archives
- Today
- Total
목록215. Kth Largest Element in an Array (1)
Scribbling
LeetCode: 215. Kth Largest Element in an Array
O(N*logK) Time Complexity Solution using heap. class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: import heapq h = [] for num in nums: if len(h) < k: heapq.heappush(h, num) else: heapq.heappush(h, num) heapq.heappop(h) return h[0] A better approach is to quick selection, runs within O(N) time on average. But this runs with O(N) memory. import random class Solution: def fin..
Computer Science/Coding Test
2021. 12. 11. 11:26