public class Solution {
public TreeNode MergeTrees(TreeNode root1, TreeNode root2) =>
root1 != null || root2 != null ?
new TreeNode(
(root1?.val ?? 0) + (root2?.val ?? 0),
MergeTrees(root1?.left, root2?.left),
MergeTrees(root1?.right, root2?.right)
)
:
null;
}
// TODO: optimize without allocating
Source: https://leetcode.com/problems/merge-two-binary-trees/
"Simplicity can't be bought later, it must be earned from the start" -- DB
Monday, March 29, 2021
Leetcode Everyday: 617. Merge Two Binary Trees. Easy
Labels:
leetcode
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment