We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
111. 二叉树的最小深度
/** * Definition for a binary tree node. * function TreeNode(val, left, right) { * this.val = (val===undefined ? 0 : val) * this.left = (left===undefined ? null : left) * this.right = (right===undefined ? null : right) * } */ /** * @param {TreeNode} root * @return {number} */ var minDepth = function (root) { if (root === null) return 0; // 叶子节点 if (root.left === null && root.right === null) return 1; //根节点 // 只有右节点 if (root.left === null) { return minDepth(root.right) + 1; } // 只有左节点 if (root.right === null) { return minDepth(root.left) + 1; } // 左右节点都有 return Math.min(minDepth(root.right), minDepth(root.left)) + 1 };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
111. 二叉树的最小深度
The text was updated successfully, but these errors were encountered: