File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed
solution/0100-0199/0100.Same Tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,31 @@ func isSameTree(p *TreeNode, q *TreeNode) bool {
144
144
}
145
145
```
146
146
147
+ ### ** JavaScript**
148
+
149
+ ``` js
150
+ /**
151
+ * Definition for a binary tree node.
152
+ * function TreeNode(val, left, right) {
153
+ * this.val = (val===undefined ? 0 : val)
154
+ * this.left = (left===undefined ? null : left)
155
+ * this.right = (right===undefined ? null : right)
156
+ * }
157
+ */
158
+ /**
159
+ * @param {TreeNode} p
160
+ * @param {TreeNode} q
161
+ * @return {boolean}
162
+ */
163
+ var isSameTree = function (p , q ) {
164
+ if (! p && ! q) return true ;
165
+ if (p && q) {
166
+ return (p .val === q .val && isSameTree (p .left , q .left ) && isSameTree (p .right , q .right ))
167
+ }
168
+ return false ;
169
+ };
170
+ ```
171
+
147
172
### ** ...**
148
173
149
174
```
Original file line number Diff line number Diff line change @@ -134,6 +134,31 @@ func isSameTree(p *TreeNode, q *TreeNode) bool {
134
134
}
135
135
```
136
136
137
+ ### ** JavaScript**
138
+
139
+ ``` js
140
+ /**
141
+ * Definition for a binary tree node.
142
+ * function TreeNode(val, left, right) {
143
+ * this.val = (val===undefined ? 0 : val)
144
+ * this.left = (left===undefined ? null : left)
145
+ * this.right = (right===undefined ? null : right)
146
+ * }
147
+ */
148
+ /**
149
+ * @param {TreeNode} p
150
+ * @param {TreeNode} q
151
+ * @return {boolean}
152
+ */
153
+ var isSameTree = function (p , q ) {
154
+ if (! p && ! q) return true ;
155
+ if (p && q) {
156
+ return (p .val === q .val && isSameTree (p .left , q .left ) && isSameTree (p .right , q .right ))
157
+ }
158
+ return false ;
159
+ };
160
+ ```
161
+
137
162
### ** ...**
138
163
139
164
```
Original file line number Diff line number Diff line change
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 && ! q ) return true ;
16
+ if ( p && q ) {
17
+ return ( p . val === q . val && isSameTree ( p . left , q . left ) && isSameTree ( p . right , q . right ) )
18
+ }
19
+ return false ;
20
+ } ;
You can’t perform that action at this time.
0 commit comments