Create 33. Search in Rotated Sorted Array.md#43
Open
fuga-98 wants to merge 1 commit into
Open
Conversation
hroc135
reviewed
May 13, 2025
| break_point = search_break() | ||
| if target <= nums[-1]: | ||
| result = bisect_left(nums, target, lo=break_point, hi=len(nums)) | ||
| if result >= len(nums) or nums[result] != target: |
There was a problem hiding this comment.
result == len(nums) の場合、target > nums[-1] なので外側の if で弾かれており、不要な条件になると思います。
hroc135
reviewed
May 13, 2025
| if result >= len(nums) or nums[result] != target: | ||
| return -1 | ||
|
|
||
| これの最初の条件いらなそう |
There was a problem hiding this comment.
compare関数の戻り値の最初の要素はnumsの末尾が必ず1になることを考慮すると、result == len(nums) になる場合は、compare(nums[i]) の結果が全て (0,0), (1,0) のいずれかになって、compare(target) の結果が (1,1) になる場合。でも、target <= nums[-1] の場合、nums[i] >= target となる i が必ず存在するので、result == len(nums) にはなり得ない、ということですね。
いらない理由を考えるのに結構頭を使ったのでコメントに書いた方が良さそうと思いました。
Owner
Author
There was a problem hiding this comment.
レビューありがとうございます。
正確に書いていただいて非常に助かります。
3回書く中でコメントを書くと大変なので省略してしまっていますが、実務なら書いたほうが良いですね。
oda
reviewed
May 13, 2025
|
|
||
| [TF,TF, TF] t= FTとなるのでresult=0となります | ||
|
|
||
| key関数の命名がうまいものが思いつかないが、実務ならdocstringで説明を書くで十分な気がしている。 |
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/search-in-rotated-sorted-array/