File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ ``` java
2
+ /**
3
+ * Definition for a binary tree node.
4
+ * public class TreeNode {
5
+ * int val;
6
+ * TreeNode left;
7
+ * TreeNode right;
8
+ * TreeNode(int x) { val = x; }
9
+ * }
10
+ */
11
+ class Solution {
12
+ public boolean isSymmetric (TreeNode root ) {
13
+ return isMirror(root, root);
14
+ }
15
+
16
+ public boolean isMirror (TreeNode t1 , TreeNode t2 ) {
17
+ if (t1 == null && t2 == null ) return true ;
18
+ if (t1 == null || t2 == null ) return false ;
19
+ return (t1. val == t2. val)
20
+ && isMirror(t1. right, t2. left)
21
+ && isMirror(t1. left, t2. right);
22
+ }
23
+ }
24
+ ```
Original file line number Diff line number Diff line change
1
+ ``` java
2
+ /**
3
+ * Definition for a binary tree node.
4
+ * public class TreeNode {
5
+ * int val;
6
+ * TreeNode left;
7
+ * TreeNode right;
8
+ * TreeNode(int x) { val = x; }
9
+ * }
10
+ */
11
+ class Solution {
12
+ public int maxDepth (TreeNode root ) {
13
+ if (root == null ){
14
+ return 0 ;
15
+ }
16
+ int leftLen = maxDepth(root. left);
17
+ int rightLen = maxDepth(root. right);
18
+ return Math . max(leftLen,rightLen)+ 1 ;
19
+
20
+ }
21
+ }
22
+ ```
You can’t perform that action at this time.
0 commit comments