153. Find Minimum in Rotated Sorted Array#40
Open
hemispherium wants to merge 4 commits into
Open
Conversation
liquo-rice
reviewed
May 8, 2026
| @@ -0,0 +1,13 @@ | |||
| ### step1 | |||
|
|
|||
| とりあえずmin_elementでいいんじゃないかと思ったら通ってしまった。調べたところO(log n)の計算量になっていそう。(https://cpprefjp.github.io/reference/algorithm/min_element.html) | |||
There was a problem hiding this comment.
ドキュメントには、以下のように記載がありますが…
計算量
max((last - first) - 1, 0) 回の比較を行う
そもそも任意の配列で最小値をO(logN)で見つけるのは可能ですかね?
Owner
Author
There was a problem hiding this comment.
失礼しました。そこに書いてある通りO(n)ですね。ソート済みなどの条件がなければ素朴に考えると全ての要素を見ないといけないと思うのでO(n)は掛かってしまいそうな気がしますね。
liquo-rice
reviewed
May 9, 2026
| @@ -0,0 +1,13 @@ | |||
| ### step1 | |||
5ky7
reviewed
May 29, 2026
| int right = nums.size() - 1; | ||
|
|
||
| while (left < right) { | ||
| int mid = left + (right -left) / 2; |
There was a problem hiding this comment.
演算子周りの空白の使い方は統一することをお勧めします
Suggested change
| int mid = left + (right -left) / 2; | |
| int mid = left + (right - left) / 2; |
| int left = 0; | ||
| int right = nums.size() - 1; | ||
|
|
||
| while (left < right) { |
There was a problem hiding this comment.
今回はnumsの中身に重複がないのでこれでも成立しますが,2分探索における区間の意味を確認しておくと良いかもしれません(典型コメント集の二分探索の項に色々まとまってます)
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/
次に解く問題:https://leetcode.com/problems/search-in-rotated-sorted-array/description/