-
Notifications
You must be signed in to change notification settings - Fork 0
153. Find Minimum in Rotated Sorted Array #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| } else if (nums[mid] < nums[right]) { | ||
| right = mid; | ||
| } else { // if (nums[mid] == nums[right]) | ||
| --right; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すべての値が等しい場合、 O(n) になるように思いました。
|
|
||
| ## 最終コード | ||
|
|
||
| 条件分岐って全部単体のifで回すよりelseとかcontinueとかつけておいた方が余計な条件分岐の判定が少なくなってちょっと早くなるとかあるんでしょうか? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
もし気になるようであれば、アセンブラーを出力させて比較したり、マイクロベンチマークを取るとよいと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど。アセンブラーを出力するのは考えませんでした。
https://godbolt.org/
このサイトでやってみたところ、x86-64 clang 20.1.0というのでやった場合は-O2, -O3といった最適化オプションを付けた場合は変わらないようです 👀
|
|
||
| 条件分岐って全部単体のifで回すよりelseとかcontinueとかつけておいた方が余計な条件分岐の判定が少なくなってちょっと早くなるとかあるんでしょうか? | ||
| コンパイラが勝手に最適化してくれたりすることもあるんですかね。 | ||
| もしかしたらこのelseは少し見づらいかも・・・ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
全体としては良いと思いました。if 文には {} ついている方が個人的には好みです。
ryosuketc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM です
問題文:
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/