Skip to content

111. Minimum Depth of Binary Tree#16

Open
hiro111208 wants to merge 1 commit into
mainfrom
111-minimum-depth-of-binary-tree
Open

111. Minimum Depth of Binary Tree#16
hiro111208 wants to merge 1 commit into
mainfrom
111-minimum-depth-of-binary-tree

Conversation

@hiro111208
Copy link
Copy Markdown
Owner

Comment thread step1.md
return 0

res = 10 ** 5
stack = [[root, 1]]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

変数名にはどんなものが入っているかを示したほうが分かりやすいかなと思います。
node_and_depthなどはいかがでしょうか。

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.

stackの変数名どうするか悩みました。

変数の中身が何かわかりやすくする場合、node_and_depthが良いと思います。他方で今回の処理がDFSであることをわかりやすくするためにはstackにしておいた方が良いとも思いました。

変数の中身のわかりやすさか処理のわかりやすさ(今回の場合DFSをしているとわかりやすく示すこと)のどちらを優先するかだと思います。

Comment thread step1.md
if root is None:
return 0

res = 10 ** 5
Copy link
Copy Markdown

@h-masder h-masder Apr 25, 2026

Choose a reason for hiding this comment

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

resの値は、将来変更される可能性が高いと思います。
どんな変数なのか、コメントアウトしておくと親切かと思います。

Comment thread step3.md
else:
stack.append((node.left, depth + 1))
stack.append((node.right, depth + 1))
return min_depth
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

今回の問題はrootから最も近い葉までの距離を求める問題ですので、
近いものから順に探索していくほうが素直かと思います。
幅優先探索を使って解いてみてもいいかもしれないですね。

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