Skip to content

Create 112. Path Sum.md#5

Merged
Mike0121 merged 1 commit intomainfrom
112.-Path-Sum
Nov 1, 2025
Merged

Create 112. Path Sum.md#5
Mike0121 merged 1 commit intomainfrom
112.-Path-Sum

Conversation

@Mike0121
Copy link
Copy Markdown
Owner

@Mike0121 Mike0121 commented May 1, 2024

No description provided.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return target == 0 のほうがシンプルだと思います。

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.

ありがとうございます。if文後、すぐにその結果をreturnするだけであれば、そのまま結果を返してしまった方がシンプルですね。頭に入れておきます。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return root.val == targetSum のほうがシンプルだと思います。

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.

ありがとうございます。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

target -= node.val のほうがシンプルだと思います。

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.

ご指摘のとおりですね、ありがとうございます。

Copy link
Copy Markdown
Owner Author

@Mike0121 Mike0121 May 1, 2024

Choose a reason for hiding this comment

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

By Odaさん
最後の

node_stack = [(root, 0)]
~
node, sum_so_far = node_stack.pop()
sum_so_far += node.val
if sum_so_far == targetSum:

とするか

node_stack = [(root, targetSum)]
~
node, remain = node_stack.pop()
remain -= node.val
if remain == 0:

とするかのほうが読みやすい気がします。

Comment on lines 38 to 39
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

これインデントおかしいですかね。

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.left is Noneまたはnot root.leftの方が良いと思います。

@Mike0121 Mike0121 changed the title 112. Path Sum.md Create 112. Path Sum.md Nov 1, 2025
@Mike0121 Mike0121 merged commit eec87fa into main Nov 1, 2025
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.

3 participants