-
Notifications
You must be signed in to change notification settings - Fork 0
【Grind75Hard】4問目295. Find Median from Data Stream #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| def addNum(self, num: int) -> None: | ||
| index = bisect_left(self.nums, num) | ||
| self.nums.insert(index, num) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def findMedian(self) -> float: | ||
| if len(self.nums) % 2: | ||
| return float(self.nums[len(self.nums) // 2]) | ||
| else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
私はインデントを落としますが、これは趣味の範囲でしょう。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あ、else不要でしたね。
書いているときは気付けなかったのですが、ない方が読みやすいと思いました。
| self.nums.insert(index, num) | ||
|
|
||
| def findMedian(self) -> float: | ||
| if len(self.nums) % 2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
私は、これは == 1 を書きますが、これも趣味です。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一瞬どっちか分からなくなるので、趣味の範囲なら==1書くようにします。
| @@ -0,0 +1,16 @@ | |||
| class MedianFinder: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Level 3でsorted arrayに挿入の解法を選んだ理由はありますか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
アルゴリズムの分かりやすさと実装の容易さで選びました。
level1のheapの解法の方が高速ですが、分かりづらいかと思いやめました。
問題
https://leetcode.com/problems/find-median-from-data-stream/