-
🎵 617. Merge Two Binary Trees javaLeetCode_Study_Plan/Algorithm 2022. 12. 26. 13:00
https://leetcode.com/problems/merge-two-binary-trees/
Merge Two Binary Trees - LeetCode
Merge Two Binary Trees - You are given two binary trees root1 and root2. Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree.
leetcode.com
public class Solution { public TreeNode mergeTrees(TreeNode t1, TreeNode t2) { if (t1 == null) return t2; if (t2 == null) return t1; t1.val += t2.val; t1.left = mergeTrees(t1.left, t2.left); t1.right = mergeTrees(t1.right, t2.right); return t1; } }
'LeetCode_Study_Plan > Algorithm' 카테고리의 다른 글
🎵542. 01 Matrix java (0) 2022.12.27 116. Populating Next Right Pointers in Each Node (0) 2022.12.26 695. Max Area of Island java (0) 2022.12.22 733. Flood Fill java (0) 2022.12.22 3. Longest Substring Without Repeating Characters java (0) 2022.12.21