728x90
https://leetcode.com/problems/merge-two-binary-trees/
Merge Two Binary Trees - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
동일한 위치의 노드를 더하는 간단한 문제
var mergeTrees = function(root1, root2) {
if(root1 === null){
return root2
}
if(root2 === null){
return root1
}
root1.val += root2.val;
root1.left = mergeTrees(root1.left, root2.left);
root1.right = mergeTrees(root1.right, root2.right);
return root1;
};
728x90
'코테' 카테고리의 다른 글
큰 수 만들기 (0) | 2022.06.13 |
---|---|
[leetcode] 1254. Number of Closed Islands (0) | 2022.06.04 |
[leetCode] 695. Max Area of Island (0) | 2022.06.02 |
애니어그램 (0) | 2022.05.16 |
짝지어 제거하기 (0) | 2022.05.14 |