Skip to content

Conversation

@Satorien
Copy link
Owner


## Step 3. Final Solution

- シンプルな実装に落ち着いた
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

Choose a reason for hiding this comment

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

確かにnums[right]ではなく、nums[0]やnums[-1]で固定した方が考える負荷が少し下がるかもしれないですね。

else:
left = middle + 1
return nums[left]
```
Copy link

@fuga-98 fuga-98 Aug 14, 2025

Choose a reason for hiding this comment

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

別のところで講師の方されていた質問です。考えてみると理解が深まるかもしれません!

  1. 「2で割る処理がありますがこれは切り捨てでも切り上げでも構わないのでしょうか。」
  2. 「nums[middle] <= nums[right] とありますが、これは < でもいいですか。」
  3. 「nums[right] は、nums[-1] でもいいですか。」
  4. 「right の初期値は nums.size() でもいいですか。」

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。

  1. この実装なら問題なさそうです。切り下げで上手くいかないのは、下から詰める処理が先に行われてしまうとき。切り上げが上手くいかないのは、上から詰める処理が先に行われてしまうとき。ということだと思うのでここだけ気を付けます。
  2. =が入っている方を先に処理する場合は、1.のところで考えたことを同じように意識します。今回は切り下げなら問題ないですが、切り上げなら=を入れられないです。
  3. 問題ないです。
  4. 上側の更新をmiddle + 1にして、終了条件をleft +1 == 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