Skip to content

112. Path Sum#27

Open
Ryotaro25 wants to merge 2 commits intomainfrom
problem25
Open

112. Path Sum#27
Ryotaro25 wants to merge 2 commits intomainfrom
problem25

Conversation

@Ryotaro25
Copy link
Copy Markdown
Owner

問題へのリンク
https://leetcode.com/problems/path-sum/description/
問題文(プレミアムの場合)

備考

次に解く問題の予告
Binary Tree Level Order Traversal

フォルダ構成
LeetCodeの問題ごとにフォルダを作成します。
フォルダ内は、step1.cpp、step2.cpp、step3.cpp、recursion.cppとrecursion_step2.cppとmemo.mdとなります。

memo.md内に各ステップで感じたことを追記します。

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.

gitignoreの設定誤って履歴消せなくなりました。

if (!root) {
return false;
}
if (!root->left && !root->right && root->val == targetSum) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

個人的には targetSum - root->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.

@oda
レビューありがとうございます。
確かに他の箇所はtargetSum - root->valとしているので修正しました。

class Solution {
public:
bool hasPathSum(TreeNode* root, int targetSum) {
queue<NodeAndSum> candidates;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

stack でもいいかもしれませんね。私はどちらでもいい場合は、stack を好みます。構造が単純なので。

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.

@oda
一度覚えたqueueを使い回しておりました。
他の構造も使えないか検討しないとですね。stackでも実装してみました。
queueと同じくemplaceを採用しました。

@TORUS0818
Copy link
Copy Markdown

拝見しました。
既存のコメント以外は良いと思いました。

@Ryotaro25
Copy link
Copy Markdown
Owner Author

@TORUS0818
レビューありがとうございます。
指摘箇所修正しました。

Copy link
Copy Markdown

@kazukiii kazukiii left a comment

Choose a reason for hiding this comment

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

既にコメントが付いているところ以外良いと思いました。読みやすかったです。

@nittoco
Copy link
Copy Markdown

nittoco commented Aug 24, 2024

見ました!良いと思いました!

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.

5 participants