Open
Conversation
arahi10
reviewed
Mar 1, 2026
| - 重複している値はない | ||
| - 出力 | ||
| - 高さがバランスした2分木 | ||
| - 二つの木の高さの差が高々1である |
arahi10
reviewed
Mar 1, 2026
| - leetcode にある回答は基本的に同じだった | ||
| - mid の取り方でもう一方の構造の木になる | ||
| - mid = len / 2 | ||
| - 0-indexで考えるか1-indexで考えるかの違いと理解した |
There was a problem hiding this comment.
「左側と右側の部分木のそれぞれの頂点数の和が奇数になるとき、そのどちらを1だけ大きくするか」に対応すると思います。
全ての部分木について再帰的に成り立ちます。
arahi10
reviewed
Mar 1, 2026
|
|
||
| - 子の情報をキューに入れるときにチェックする必要があった | ||
| - 量が多くなるので、基本は再帰で実装すると思った | ||
| - メモリ観点でも再帰の方が少なそう |
There was a problem hiding this comment.
キューによるBFSからスタックによるDFSに変更すると、"jobs" のサイズは
|
GoLongあまり詳しくないので質問するのですが、今回のようにキューとしてスライスを使った場合、スライスのキャパシティは増え続ける、と言う認識で良いでしょうか? |
Owner
Author
|
ありがとうございます。 go ではスライスを拡大するタイミングで、現在有効な要素についてコピーするため、すでに不要になった分は除外されます。そのため、使われない領域が増え続けるという挙動にはならないという理解をしています。 |
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.
今回の問題
Convert Sorted Array to Binary Search Tree - LeetCode
使用言語
Go
次に解く問題
Path Sum - LeetCode