Merged
Conversation
hayashi-ay
reviewed
May 13, 2024
hayashi-ay
left a comment
There was a problem hiding this comment.
凄く気になるところはなかったです。あとは半開区間で書いても良いかもくらいですかね。
| def search(self, nums: List[int], target: int) -> int: | ||
| left = 0 | ||
| right = len(nums) - 1 | ||
| while right - left > 1: |
There was a problem hiding this comment.
while left > rightとかの方が素直だと思うんですよね。あえて引き算する必要がないというか。
Owner
Author
There was a problem hiding this comment.
コメントありがとうございます!
自分的には、差を求めることによって区間幅を連想しやすくなるのでこうしてますね
右辺が0の場合はleft < rightでもすぐわかるのですが、left + 1 < rightだと自分は一度頭で変換しないと解釈できないです。
shining-ai
reviewed
May 13, 2024
| def search(self, nums: List[int], target: int) -> int: | ||
| left = 0 | ||
| right = len(nums) - 1 | ||
| while right - left >= 0: |
There was a problem hiding this comment.
この条件は、while left <= right:の方が閉区間の条件だとパッと見て分かると思いました。
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/description
参考:
https://leetcode.com/problems/search-in-rotated-sorted-array/solutions/3879263/100-binary-search-easy-video-o-log-n-optimal-solution/?envType=problem-list-v2&envId=me1nua2e
https://github.com/SuperHotDogCat/coding-interview/pull/10/files