mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 18:23:52 +00:00
Update 28. 对称的二叉树.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
+6
-6
@@ -1,6 +1,6 @@
|
||||
# 28. 对称的二叉树
|
||||
|
||||
[NowCoder](https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb?tpId=13&tqId=11211&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
|
||||
[Leetcode](https://leetcode.cn/problems/dui-cheng-de-er-cha-shu-lcof/)
|
||||
|
||||
## 题目描述
|
||||
|
||||
@@ -9,19 +9,19 @@
|
||||
## 解题思路
|
||||
|
||||
```java
|
||||
boolean isSymmetrical(TreeNode pRoot) {
|
||||
if (pRoot == null)
|
||||
public boolean checkSymmetricTree(TreeNode root) {
|
||||
if (root == null)
|
||||
return true;
|
||||
return isSymmetrical(pRoot.left, pRoot.right);
|
||||
return checkSymmetricTree(root.left, root.right);
|
||||
}
|
||||
|
||||
boolean isSymmetrical(TreeNode t1, TreeNode t2) {
|
||||
private boolean checkSymmetricTree(TreeNode t1, TreeNode t2) {
|
||||
if (t1 == null && t2 == null)
|
||||
return true;
|
||||
if (t1 == null || t2 == null)
|
||||
return false;
|
||||
if (t1.val != t2.val)
|
||||
return false;
|
||||
return isSymmetrical(t1.left, t2.right) && isSymmetrical(t1.right, t2.left);
|
||||
return checkSymmetricTree(t1.left, t2.right) && checkSymmetricTree(t1.right, t2.left);
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user