108. Convert Sorted Array to Binary Search Tree - #24
Open
hiroki-horiguchi-dev wants to merge 1 commit into
Open
Conversation
tom4649
reviewed
Jun 4, 2026
| if (left >= right) { | ||
| return null; | ||
| } | ||
| int middle = (left + right) / 2; |
There was a problem hiding this comment.
int middle = left + (right - left) / 2; とするとオーバーフロー対策にはなりそうです
Owner
Author
There was a problem hiding this comment.
ありがとうございます、極端に大きい nums について考える時はおっしゃる通り、その通りです。
今回の問題は 10^4 が最大値なので、コールスタックに積むのは14程度になるので問題としては考慮不要として解いていました。
Owner
Author
There was a problem hiding this comment.
失礼しました。
ここでいただいている指摘は整数オーバーフローの方ですね。制約の通り、この問題ではオーバーフローしませんが、日常的に書いておくべきことだと思いました。
ありがとうございます。
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.
108. Convert Sorted Array to Binary Search Treeを解きました