LeetCode 솔루션 분류 [5/23] 703. Kth Largest Element in a Stream 작성자 정보 mingki 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 작성 작성일 2023.05.22 20:21 컨텐츠 정보 8,587 조회 2 댓글 0 추천 0 비추천 목록 관리 글검색 게시글 쓰기 본문 703. Kth Largest Element in a Stream 0 추천 0 비추천 SNS 공유 태그 #Tree, #Design, #Binary Search, #Tree Heap (Priority Queue), #Binary Tree, #Data Stream 관련자료 링크 https://leetcode.com/problems/kth-largest-element-in-a-stream/description/ 1022 회 연결 댓글 2 mingki님의 댓글 익명 작성일 2023.05.22 20:22 답글 추천 0 비추천 0 [https://svkoreans.com/data/editor/2305/cmt_1235111808_iSCz49fc_acdb28eda4459a552a378b74b963327ee9cf3a9a.png] JayShin님의 댓글 익명 작성일 2023.05.22 20:46 # Time Complexity: O(log n), Space Complexity: O(k) class KthLargest: def __init__(self, k: int, nums: List[int]): self.k = k self.heap = [] for num in nums: self.add(num) def add(self, val: int) -> int: heapq.heappush(self.heap, val) if (len(self.heap) > self.k): heapq.heappop(self.heap) return self.heap[0] Copy 답글 추천 0 비추천 0 [code=python]# Time Complexity: O(log n), Space Complexity: O(k) class KthLargest: def __init__(self, k: int, nums: List[int]): self.k = k self.heap = [] for num in nums: self.add(num) def add(self, val: int) -> int: heapq.heappush(self.heap, val) if (len(self.heap) > self.k): heapq.heappop(self.heap) return self.heap[0] [/code] Select File Upload File 목록 관리 글검색 게시글 쓰기
mingki님의 댓글 익명 작성일 2023.05.22 20:22 답글 추천 0 비추천 0 [https://svkoreans.com/data/editor/2305/cmt_1235111808_iSCz49fc_acdb28eda4459a552a378b74b963327ee9cf3a9a.png]
JayShin님의 댓글 익명 작성일 2023.05.22 20:46 # Time Complexity: O(log n), Space Complexity: O(k) class KthLargest: def __init__(self, k: int, nums: List[int]): self.k = k self.heap = [] for num in nums: self.add(num) def add(self, val: int) -> int: heapq.heappush(self.heap, val) if (len(self.heap) > self.k): heapq.heappop(self.heap) return self.heap[0] Copy 답글 추천 0 비추천 0 [code=python]# Time Complexity: O(log n), Space Complexity: O(k) class KthLargest: def __init__(self, k: int, nums: List[int]): self.k = k self.heap = [] for num in nums: self.add(num) def add(self, val: int) -> int: heapq.heappush(self.heap, val) if (len(self.heap) > self.k): heapq.heappop(self.heap) return self.heap[0] [/code]