Skip to content

Conversation

@shining-ai
Copy link
Owner


def addNum(self, num: int) -> None:
index = bisect_left(self.nums, num)
self.nums.insert(index, num)
Copy link

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:
Copy link

Choose a reason for hiding this comment

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

私はインデントを落としますが、これは趣味の範囲でしょう。

Copy link
Owner Author

@shining-ai shining-ai May 10, 2024

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:
Copy link

Choose a reason for hiding this comment

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

私は、これは == 1 を書きますが、これも趣味です。

Copy link
Owner Author

@shining-ai shining-ai May 10, 2024

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:
Copy link

@liquo-rice liquo-rice May 10, 2024

Choose a reason for hiding this comment

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

Level 3でsorted arrayに挿入の解法を選んだ理由はありますか?

Copy link
Owner Author

Choose a reason for hiding this comment

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

アルゴリズムの分かりやすさと実装の容易さで選びました。
level1のheapの解法の方が高速ですが、分かりづらいかと思いやめました。

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