剑指Offer_39 发表于 2017-12-04 | 分类于 剑指Offer 题目输入一棵二叉树,判断该二叉树是否是平衡二叉树。 解题思路二叉树的后序遍历 123456789101112131415161718192021222324252627public class Solution { private boolean isBalance = true; private int depth(TreeNode node){ if(node == null){ return 0; } int left = depth(node.left); int right = depth(node.right); if(Math.abs(left - right) > 1){ isBalance = false; } //返回左右子树的父节点的深度 return left > right ? left + 1 : right + 1; } public boolean IsBalanced_Solution(TreeNode root) { if(root == null){ return true; } depth(root); return isBalance; } }