We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 998af8d + 22e46f8 commit 8616f61Copy full SHA for 8616f61
LeetCode/100. Same Tree/Solution.java
@@ -0,0 +1,29 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * public class TreeNode {
4
+ * int val;
5
+ * TreeNode left;
6
+ * TreeNode right;
7
+ * TreeNode() {}
8
+ * TreeNode(int val) { this.val = val; }
9
+ * TreeNode(int val, TreeNode left, TreeNode right) {
10
+ * this.val = val;
11
+ * this.left = left;
12
+ * this.right = right;
13
+ * }
14
15
+ */
16
+class Solution {
17
+ public boolean isSameTree(TreeNode p, TreeNode q) {
18
+ if (p == null && q == null){
19
+ return true;
20
+ }
21
+ if(p == null || q == null){
22
+ return false;
23
24
+ if(p.val!=q.val){
25
26
27
+ return isSameTree(p.right,q.right)&& isSameTree(p.left,q.left);
28
29
+}
0 commit comments