Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d756fe9

Browse files
author
zongyanqi
committed
add Easy_100_Same_Tree
1 parent 984e54f commit d756fe9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Easy_100_Same_Tree.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Given two binary trees, write a function to check if they are equal or not.
3+
4+
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
5+
*/
6+
7+
/**
8+
* Definition for a binary tree node.
9+
* function TreeNode(val) {
10+
* this.val = val;
11+
* this.left = this.right = null;
12+
* }
13+
*/
14+
/**
15+
* @param {TreeNode} p
16+
* @param {TreeNode} q
17+
* @return {boolean}
18+
*/
19+
var isSameTree = function (p, q) {
20+
21+
if (!p && !q) return true;
22+
if (!p || !q) return false;
23+
if (p.val !== q.val) return false;
24+
25+
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
26+
27+
};
28+
29+

0 commit comments

Comments
 (0)