We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 984e54f commit d756fe9Copy full SHA for d756fe9
Easy_100_Same_Tree.js
@@ -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