Symmetric Tree TotalA
来源:互联网 发布:淘宝香港高登iphone 编辑:程序博客网 时间:2024/06/11 02:44
Symmetric Tree Total
code
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public boolean isSymmetric(TreeNode root) { if (root == null) { return true; } else{ return new Solution().ABisSymmetric(root.left,root.right); } } public boolean ABisSymmetric(TreeNode A, TreeNode B) { Solution sl = new Solution(); if (A == null && B == null) { return true; } else if (A == null || B == null) { return false; } else { if (A.val == B.val && sl.ABisSymmetric(A.left,B.right) && sl.ABisSymmetric(A.right,B.left) ) { return true; } else { return false; } } }}
-1.30
1.别人的代码,引入比较两棵树相等的算法,递归实现,分A.左右都空 B.左空C.右空 D.左右都不空四种情况。
2.左右都不空情况下,左右数值相等 && 子树对应相等才返回真。
3.此递归的base情况是两个单元素树的比较
0 0
- Symmetric Tree TotalA
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- Symmetric Tree
- error while loading shared librarieserror while loading shared libraries: : libz.so.1
- three.js 源码注释(七十八)extras/geometries/IcosahedronGeometry.js
- POJ 题目1256 Anagram(next_permutation)
- 编译Android4.4.2源码 error while loading shared libraries: libstdc++.so.6
- 扩充数组方案实现
- Symmetric Tree TotalA
- boost info_parse_read.hpp isspace BUG修正
- iOS设备的流量分析:Remote Virtual Interface
- Xcode提示“Valid signing identity not found”的解决方法
- 深入解析JVM内存区域组成
- Vehicle Type Classification Using Semi-Supervised Convolutional Neural Network(泛读)
- poj1195 Mobile phones 二维树状数组
- ubuntu14.10 安装问题
- 试试看