Skip to content

108. Convert Sorted Array to Binary Search Tree - #24

Open
hiroki-horiguchi-dev wants to merge 1 commit into
mainfrom
tree-bst-108
Open

108. Convert Sorted Array to Binary Search Tree#24
hiroki-horiguchi-dev wants to merge 1 commit into
mainfrom
tree-bst-108

Conversation

@hiroki-horiguchi-dev

Copy link
Copy Markdown
Owner

@hiroki-horiguchi-dev hiroki-horiguchi-dev self-assigned this Jun 4, 2026
Comment thread tree-bst/108.md
if (left >= right) {
return null;
}
int middle = (left + right) / 2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

int middle = left + (right - left) / 2; とするとオーバーフロー対策にはなりそうです

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます、極端に大きい nums について考える時はおっしゃる通り、その通りです。
今回の問題は 10^4 が最大値なので、コールスタックに積むのは14程度になるので問題としては考慮不要として解いていました。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

失礼しました。
ここでいただいている指摘は整数オーバーフローの方ですね。制約の通り、この問題ではオーバーフローしませんが、日常的に書いておくべきことだと思いました。
ありがとうございます。

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.

2 participants