Skip to content

Conversation

@docto-rin
Copy link
Owner

import bisect


class BinaryView(collections.abc.Sequence):

Choose a reason for hiding this comment

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

Viewクラスの実装という手段もあるのですね、勉強になります。

right = len(nums) - 1 # i >= right, nums[i] <= nums[-1]
while left < right:
mid = (left + right) // 2
if nums[mid] > nums[-1]:

Choose a reason for hiding this comment

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

私は最後に返したほうの不変条件を分かりやすくするために、最後に返す方を先に書くのですがこれは好みかもしれません。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。

なるほど、いいアイデアですね。

今まで何も考えずleft, rightの順で書いてましたが、返り値に使う方の命題を先に書いた方が読みやすいです。

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