Open pwstrick opened 4 years ago
104. 二叉树的最大深度
/** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } */ /** * @param {TreeNode} root * @return {number} */ var maxDepth = function(root) { if(root == null) return 0; return max(maxDepth(root.left) + 1, maxDepth(root.right) + 1); }; function max(left, right) { if(left > right) return left; return right; }
104. 二叉树的最大深度