Open
Conversation
oda
reviewed
Feb 15, 2026
| t1がnullptrならt2を直接渡してしまえばメモリ節約できるともいわれたが、deleteが大変すぎるので採用しない。 | ||
| 他の方を見たらbfsや親から子に伝搬する形で書く人が多いか | ||
| https://discord.com/channels/1084280443945353267/1295357747545505833/1329746604114055191 | ||
| はtreeがn個になったときに綺麗だが、cppらしい書き方はわからない。lambdaとかか? |
There was a problem hiding this comment.
reference が取れるのでもっと簡単に書けるはずです。
std::pair<TreeNode**, std::vector<TreeNode*>> をスタックに積んでみましょう。
また、メンバーポインターという面白い文法があったりします。
TreeNode* TreeNode::* branches[] = { &TreeNode::left, &TreeNode::right };
Owner
Author
There was a problem hiding this comment.
まずメンバポインタを知りませんでした。
勉強なので両方書いてみます、ありがとうございます!
mamo3gr
reviewed
Feb 17, 2026
| root1あるいはroot2のどっちかにノードがあるならノードを作成して値を入れる というのがやること。 | ||
| 今回作る関数はheadを返すだけなのでdeleteは関数ユーザーの責任。 | ||
| nullptr参照に気を付けるべき。とくにroot1とroot2の深さが2以上違う場合。 | ||
| leetcodeの引数名をleftRoot, rightRootにする。 |
There was a problem hiding this comment.
これが leftLeft のような分かりにくい変数名の原因になっています。もとのシグネチャならそれほど気にならないように思いました(それでも left1 のようなベタ書き感はあるんですが)。
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.
三項演算子を多用したAIの回答が読みやすかったです。
三項演算子を見ていると、やっぱりifは文ではなく式だよなって思いました。(ifを式とするrustからは、コンパイル通せないので目をそらしつつ)