153. Find Minimum in Rotated Sorted Array#44
Open
skypenguins wants to merge 1 commit into
Open
Conversation
h-masder
reviewed
Jul 6, 2026
| class Solution: | ||
| def findMin(self, nums: List[int]) -> int: | ||
| return min(nums) | ||
| ``` |
There was a problem hiding this comment.
丁寧に実行時間の見積もりをしたほうが良いかと思います。
CPythonを見ると、minの計算量自体はO(N)のようです(Nはnumsの長さ)
https://github.com/python/cpython/blob/main/Python/bltinmodule.c#L2087
このアプローチのポイントは、「N が十分小さいのであれば、線形探索でも要求される実行時間内で処理が完了する、もしくは、線形探索の方が二分探索などの別の手法と比べて(実装が単純で)実行時間も速い」という点だと思います。
Nの長さがどの程度まではこの手法を採用し、それを超える場合は別の手法を検討すべきなのか、という観点で考えるとよいと思います。
また、将来的に numsがどの程度の大きさまで増える可能性があるのか、想定するアプリケーションやユースケースを踏まえて考えることも重要だと思います。
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.
153. Find Minimum in Rotated Sorted Array
次回予告: 198. House Robber