Skip to content

153. Find Minimum in Rotated Sorted Array#40

Open
hemispherium wants to merge 4 commits into
mainfrom
0153-find-minimum-in-rotated-sorted-array
Open

153. Find Minimum in Rotated Sorted Array#40
hemispherium wants to merge 4 commits into
mainfrom
0153-find-minimum-in-rotated-sorted-array

Conversation

@hemispherium
Copy link
Copy Markdown
Owner

@@ -0,0 +1,13 @@
### step1

とりあえずmin_elementでいいんじゃないかと思ったら通ってしまった。調べたところO(log n)の計算量になっていそう。(https://cpprefjp.github.io/reference/algorithm/min_element.html)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ドキュメントには、以下のように記載がありますが…

計算量
max((last - first) - 1, 0) 回の比較を行う

そもそも任意の配列で最小値をO(logN)で見つけるのは可能ですかね?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

失礼しました。そこに書いてある通りO(n)ですね。ソート済みなどの条件がなければ素朴に考えると全ての要素を見ないといけないと思うのでO(n)は掛かってしまいそうな気がしますね。

Comment thread 0322-coin-change/memo.md Outdated
@@ -0,0 +1,13 @@
### step1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

関係ないファイルが入っています。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

失礼しました。消しました。

int right = nums.size() - 1;

while (left < right) {
int mid = left + (right -left) / 2;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

演算子周りの空白の使い方は統一することをお勧めします

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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

今回はnumsの中身に重複がないのでこれでも成立しますが,2分探索における区間の意味を確認しておくと良いかもしれません(典型コメント集の二分探索の項に色々まとまってます)

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