File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 60
60
88|[ Merge Sorted Array] ( ./0088-merge-sorted-array.js ) |Easy|
61
61
94|[ Binary Tree Inorder Traversal] ( ./0094-binary-tree-inorder-traversal.js ) |Easy|
62
62
98|[ Validate Binary Search Tree] ( ./0098-validate-binary-search-tree.js ) |Medium|
63
+ 100|[ Same Tree] ( ./0100-same-tree.js ) |Easy|
63
64
101|[ Symmetric Tree] ( ./0101-symmetric-tree.js ) |Easy|
64
65
102|[ Binary Tree Level Order Traversal] ( ./0102-binary-tree-level-order-traversal.js ) |Medium|
65
66
104|[ Maximum Depth of Binary Tree] ( ./0104-maximum-depth-of-binary-tree.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 100. Same Tree
3
+ * https://leetcode.com/problems/same-tree/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given the roots of two binary trees p and q, write a function to check if they are
7
+ * the same or not.
8
+ *
9
+ * Two binary trees are considered the same if they are structurally identical, and
10
+ * the nodes have the same value.
11
+ */
12
+
13
+ /**
14
+ * Definition for a binary tree node.
15
+ * function TreeNode(val, left, right) {
16
+ * this.val = (val===undefined ? 0 : val)
17
+ * this.left = (left===undefined ? null : left)
18
+ * this.right = (right===undefined ? null : right)
19
+ * }
20
+ */
21
+ /**
22
+ * @param {TreeNode } p
23
+ * @param {TreeNode } q
24
+ * @return {boolean }
25
+ */
26
+ var isSameTree = function ( p , q ) {
27
+ const hasSameValue = p !== null && q !== null && p . val === q . val ;
28
+ const hasSameTree = hasSameValue && isSameTree ( p . left , q . left ) && isSameTree ( p . right , q . right ) ;
29
+ return ( p === null && q === null ) || hasSameTree ;
30
+ } ;
You can’t perform that action at this time.
0 commit comments