Skip to content

703. Kth Largest Element in a Stream#9

Open
tNita wants to merge 1 commit into
mainfrom
add/703_kth_largest_element_in_a_stream
Open

703. Kth Largest Element in a Stream#9
tNita wants to merge 1 commit into
mainfrom
add/703_kth_largest_element_in_a_stream

Conversation

@tNita
Copy link
Copy Markdown
Owner

@tNita tNita commented Feb 2, 2026

@tNita tNita changed the title solve: 703 kth largest element in a stream 703 kth largest element in a stream Feb 2, 2026
@tNita tNita changed the title 703 kth largest element in a stream 703. Kth Largest Element in a Stream Feb 2, 2026
class MyHeap:
def __init__(self, data: list):
self.heap = data
self.heapify()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらのコメントをご参照ください。
Hiroto-Iizuka/coding_practice#17 (comment)


class KthLargest:
def __init__(self, k: int, nums: List[int]):
if k < 0 or k > len(nums) + 1:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if not 0 <= k <= len(nums) + 1:

と数直線上に一直線になるように並べると、読みやすくなると思います。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

確かに頭の中に数直線をイメージしやすくなりそうですね。ありがとうございます。

- 二分探索は標準ライブラリがあるのでそちらを使う(https://docs.python.org/3/library/bisect.html)
- ただし、昇順でソートされた配列にしか適用できないので、昇順で点数配列を持っておき、後ろからk番目を答えとする必要あり
- https://github.com/python/cpython/issues/87466
- (脱線:てかこのイシューをあげている人、提案の幅が広いな。これが専門家の選択肢の幅の広さなのかな)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

リサーチでイシューまで確認しているのは良い動きだなと感じました。

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.

3 participants