Skip to content

110. Balanced Binary Tree#78

Open
kitano-kazuki wants to merge 1 commit into
mainfrom
110-balanced-binary-tree
Open

110. Balanced Binary Tree#78
kitano-kazuki wants to merge 1 commit into
mainfrom
110-balanced-binary-tree

Conversation

@kitano-kazuki
Copy link
Copy Markdown
Owner

Comment thread memo.md

## アプローチ

* highed-balancedかどうかを判定する
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

高さなのでheightですね(一応)

Comment thread memo.md
def isBalanced(self, root: Optional[TreeNode]) -> bool:
def is_balanced_helper(root: TreeNode | None) -> tuple[int, bool]:
if root is None:
return 1, True
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

これは再帰の起点なので1始まりでも結果的に影響は出ないのですが、heightとしては0が正しいのではないでしょうか?
(平衡の計算は相対的なずれだけなので、起点が常に1になっていても計算上のずれはなく、たとえば1を255とかにしても正しく動作します)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants