Skip to content

Conversation

KentaroJay
Copy link
Owner

問題へのリンク(URL To The Problem)

https://leetcode.com/problems/find-minimum-in-rotated-sorted-array?envType=problem-list-v2&envId=xo2bgr0r

問題文概要(Problem Description)

image

次に解く問題の予告(Announcement For The Next Problem)

https://leetcode.com/problems/move-zeroes?envType=problem-list-v2&envId=xo2bgr0r

レコーディング(Recording)

https://youtu.be/UQUWyZVNur0

Comment on lines +61 to +62
全体的に、`left` と `right` の間の範囲が閉区間か開区間かを
考慮していなかったことがわかりました。
Copy link

@Kazuryu0907 Kazuryu0907 Sep 13, 2025

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

  1. 二分探索を、 [false, false, false, ..., false, true, true, ture, ..., true] と並んだ配列があったとき、 false と true の境界の位置を求める問題、または一番左の true の位置を求める問題と捉えているか?
  2. 位置を求めるにあたり、答えが含まれる範囲を狭めていく問題と捉えているか?
  3. 範囲を考えるにあたり、閉区間・開区間・半開区間の違いを理解できているか?
  4. 用いた区間の種類に対し、適切な初期値を、理由を理解したうえで、設定できるか?
  5. 用いた区間の種類に対し、適切なループ不変条件を、理由を理解したうえで、設定できるか?
  6. 用いた区間の種類に対し、範囲を狭めるためのロジックを、理由を理解したうえで、適切に記述できるか?

個人的に、ここの質問が役に立ったので、共有します

Copy link
Owner Author

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` に設定すれば
それが修正されることには自分では気づけないと思いました。
Copy link

Choose a reason for hiding this comment

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

私が、考えるべきことだと思っているのは、

  1. 入力はこういう制約のものである
  2. そこに、left, right という変数を置く、これはこういう不変条件を満たす変数である
  3. ループを回すときに、middle という位置について計算をする、それは left, right との大小関係等こういう性質を持っている
  4. middle での値によって、left, right をこのように更新すると、不変条件を満たしたままにできる
  5. 更新をしていくと while をこういう条件で抜ける、この際にある式で表される値は left, right の不変条件から求めるものになっている
  6. これが必ず停止することは、ある値が狭義単調減少であることから言える

https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.c15qprmvxkc2

Copy link
Owner Author

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` の間の範囲が閉区間か開区間かを
Copy link

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

@KentaroJay KentaroJay merged commit 1d5f78f into main Sep 24, 2025
1 check passed
@KentaroJay KentaroJay deleted the problem/find-minimum-in-rotated-sorted-array branch September 24, 2025 12:13
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