Skip to content

703. Kth Largest Element in a Stream#8

Open
rimokem wants to merge 1 commit into
mainfrom
0703-kth-largest-element-in-a-stream
Open

703. Kth Largest Element in a Stream#8
rimokem wants to merge 1 commit into
mainfrom
0703-kth-largest-element-in-a-stream

Conversation

@rimokem
Copy link
Copy Markdown
Owner

@rimokem rimokem commented Mar 29, 2026

Comment thread 0703/memo.md
Comment on lines +78 to +80
self.largest_k = []
for num in nums:
self.add(num)
Copy link
Copy Markdown

@tom4649 tom4649 Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全てheapに入れるのではなく、ソートしてk個だけheapに入れるのでも良いと思います。好みの問題かもしれません(自分が受けたコメントです)。

Comment thread 0703/memo.md
if len(self.largest_k) > self.k:
heapq.heappop(self.largest_k)
return self.largest_k[0]
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xbam326/leetcode#20 (comment)

こちらご参考にしてみてください

Comment thread 0703/memo.md
class KthLargest:
def __init__(self, k: int, nums: List[int]):
self.k = k
self.largest_k = nums
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好みだと思いますが、kth_largestなどのほうがよりわかりやすいのではないかと感じました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants