101. Symmetric Tree

Posted gopanama

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了101. Symmetric Tree相关的知识,希望对你有一定的参考价值。

https://leetcode.com/problems/symmetric-tree/discuss/166375/Java-Accepted-very-simple-solution

 

 1 class Solution {
 2     StringBuilder sb1 = new StringBuilder();
 3     StringBuilder sb2 = new StringBuilder();
 4     public boolean isSymmetric(TreeNode root) {
 5         if(root == null) return true;
 6         leftR(root);
 7         rightR(root);
 8         if(sb1.toString().equals(sb2.toString())) {
 9             return true;
10         }else {
11             return false;
12         }
13         
14     }
15    
16     public void leftR(TreeNode root) {
17         if(root != null) {
18             leftR(root.left);
19             sb1.append("l");
20             sb1.append(root.val);
21             leftR(root.right);
22             sb1.append("r");
23         }
24             
25         
26  }
27     
28     public void rightR(TreeNode root) {
29         if(root != null) {
30             rightR(root.right);
31             sb2.append("r");
32             sb2.append(root.val);
33             rightR(root.left);
34             sb2.append("l");
35         }
36     }   
37 }

 

以上是关于101. Symmetric Tree的主要内容,如果未能解决你的问题,请参考以下文章

101. Symmetric Tree

[LeetCode]题解(python):101-Symmetric Tree

101. Symmetric Tree

101. Symmetric Tree

LeetCode OJ 101Symmetric Tree

101. Symmetric Tree