-
Notifications
You must be signed in to change notification settings - Fork 0
Find Minimum in Rotated Sorted Array #18
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
Conversation
全体的に、`left` と `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.
https://discord.com/channels/1084280443945353267/1196498607977799853/1269532028819476562
- 二分探索を、 [false, false, false, ..., false, true, true, ture, ..., true] と並んだ配列があったとき、 false と true の境界の位置を求める問題、または一番左の true の位置を求める問題と捉えているか?
- 位置を求めるにあたり、答えが含まれる範囲を狭めていく問題と捉えているか?
- 範囲を考えるにあたり、閉区間・開区間・半開区間の違いを理解できているか?
- 用いた区間の種類に対し、適切な初期値を、理由を理解したうえで、設定できるか?
- 用いた区間の種類に対し、適切なループ不変条件を、理由を理解したうえで、設定できるか?
- 用いた区間の種類に対し、範囲を狭めるためのロジックを、理由を理解したうえで、適切に記述できるか?
個人的に、ここの質問が役に立ったので、共有します
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.
ですです自分もそこみて気づきました。ご共有ありがとうございます。
`left = -1` に設定するというアイデアをどのように思いつくかがわからないというべきか) | ||
* インデックス0が大きい部分でないときに `left = 0` に設定するのが | ||
間違っていることには気づけると思いますが、`left = -1` に設定すれば | ||
それが修正されることには自分では気づけないと思いました。 |
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.
私が、考えるべきことだと思っているのは、
- 入力はこういう制約のものである
- そこに、left, right という変数を置く、これはこういう不変条件を満たす変数である
- ループを回すときに、middle という位置について計算をする、それは left, right との大小関係等こういう性質を持っている
- middle での値によって、left, right をこのように更新すると、不変条件を満たしたままにできる
- 更新をしていくと while をこういう条件で抜ける、この際にある式で表される値は left, 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.
今回の場合であれば left, right がそれぞれ 最小の値を含まない方、含む方という不変条件を満たすものとして考えることができれば left = -1 として初期化されるべきと連想できましたね。勉強になりました。ありがとうございます。
* `middle` の値を除外できるので、 | ||
`left = middle + 1` とできることに気づきました | ||
|
||
全体的に、`left` と `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.
inclusive, exclusive で分かっているならばいいんですが、人によって違う使い方をします。
https://discord.com/channels/1084280443945353267/1231966485610758196/1350728552399765555
問題へのリンク(URL To The Problem)
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array?envType=problem-list-v2&envId=xo2bgr0r
問題文概要(Problem Description)
次に解く問題の予告(Announcement For The Next Problem)
https://leetcode.com/problems/move-zeroes?envType=problem-list-v2&envId=xo2bgr0r
レコーディング(Recording)
https://youtu.be/UQUWyZVNur0