Skip to content

Commit 7885414

Browse files
committed
100. Same Tree
1 parent 57bfaa3 commit 7885414

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/100. Same Tree.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 100. Same Tree
3+
* https://leetcode.com/problems/same-tree/
4+
* Definition for a binary tree node.
5+
* function TreeNode(val) {
6+
* this.val = val;
7+
* this.left = this.right = null;
8+
* }
9+
*/
10+
/**
11+
* @param {TreeNode} p
12+
* @param {TreeNode} q
13+
* @return {boolean}
14+
*/
15+
var isSameTree = function (p, q) {
16+
if (!p && !q) {
17+
return true;
18+
}
19+
if (!p || !q) {
20+
return false;
21+
}
22+
return p.val === q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
23+
};

0 commit comments

Comments
 (0)