题解 | #二叉树的最小深度#
二叉树的最小深度
http://www.nowcoder.com/practice/e08819cfdeb34985a8de9c4e6562e724
/**
- struct TreeNode {
- int val;
- struct TreeNode *left;
- struct TreeNode *right;
- }; */
class Solution { public: /** * * @param root TreeNode类 * @return int整型 / int run(TreeNode root) { // write code here if (!root) return 0; auto l = run(root->left); auto r = run(root->right); if (!l) return r + 1; if (!r) return l + 1; return min(l, r) + 1;
}
};