Solved Arai60/153. Find Minimum in Rotated Sorted Array#42
Open
Solved Arai60/153. Find Minimum in Rotated Sorted Array#42
Conversation
fuga-98
reviewed
Aug 14, 2025
|
|
||
| ## Step 3. Final Solution | ||
|
|
||
| - シンプルな実装に落ち着いた |
Owner
Author
There was a problem hiding this comment.
確かにnums[right]ではなく、nums[0]やnums[-1]で固定した方が考える負荷が少し下がるかもしれないですね。
fuga-98
reviewed
Aug 14, 2025
| else: | ||
| left = middle + 1 | ||
| return nums[left] | ||
| ``` |
There was a problem hiding this comment.
別のところで講師の方されていた質問です。考えてみると理解が深まるかもしれません!
- 「2で割る処理がありますがこれは切り捨てでも切り上げでも構わないのでしょうか。」
- 「nums[middle] <= nums[right] とありますが、これは < でもいいですか。」
- 「nums[right] は、nums[-1] でもいいですか。」
- 「right の初期値は nums.size() でもいいですか。」
Owner
Author
There was a problem hiding this comment.
ありがとうございます。
- この実装なら問題なさそうです。切り下げで上手くいかないのは、下から詰める処理が先に行われてしまうとき。切り上げが上手くいかないのは、上から詰める処理が先に行われてしまうとき。ということだと思うのでここだけ気を付けます。
- =が入っている方を先に処理する場合は、1.のところで考えたことを同じように意識します。今回は切り下げなら問題ないですが、切り上げなら=を入れられないです。
- 問題ないです。
- 上側の更新をmiddle + 1にして、終了条件をleft +1 == rightの時にすれば行けそうです。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題文:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/