Skip to content

Commit 1602133

Browse files
committed
Same Tree / 초급
1 parent d4d1840 commit 1602133

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
var isSameTree = function (p, q) {
15+
if (p === null && q === null) {
16+
return true;
17+
}
18+
19+
if (p === null || q === null) {
20+
return false;
21+
}
22+
23+
if (p.val !== q.val) {
24+
return false;
25+
}
26+
27+
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
28+
};

0 commit comments

Comments
 (0)