leetcode 0404 浜屽弶鏍戞鏌ュ钩琛℃€?DFS
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode 0404 浜屽弶鏍戞鏌ュ钩琛℃€?DFS相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/png' title='png'>png
tco int ret lan col treenode diff 骞宠public boolean isBalanced(TreeNode root) { if (root == null) { return true; } int diff = getDepth(root.left) - getDepth(root.right); diff = diff > 0 ? diff : diff * -1; if((diff <= 1)){return false;} return isBalanced(root.right) && isBalanced(root.left); } public int getDepth(TreeNode node) { if (node == null) { return 0; } return Math.max(getDepth(node.left), getDepth(node.right)) + 1; }
以上是关于leetcode 0404 浜屽弶鏍戞鏌ュ钩琛℃€?DFS的主要内容,如果未能解决你的问题,请参考以下文章