Skip to content

Commit 5da58e8

Browse files
committed
SameTree / 기초
1 parent b56134f commit 5da58e8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val, left, right) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.left = (left===undefined ? null : left)
6+
* this.right = (right===undefined ? null : right)
7+
* }
8+
*/
9+
/**
10+
* @param {TreeNode} p
11+
* @param {TreeNode} q
12+
* @return {boolean}
13+
*/
14+
function isSameTree(p, q){
15+
if (!p && !q) return true;
16+
if (!p || !q || p.val !== q.val) return false;
17+
18+
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
19+
};

0 commit comments

Comments
 (0)