//代码还是要精简?? 发现max函数比三元运算符效率高
class Solution {
public:
int maxDepth(TreeNode* root) {
if(!root) return 0;
else return max(maxDepth(root->left),maxDepth(root->right))+1;
}
};
50 - 算法- LeetCode 104 -二叉树
最新推荐文章于 2024-04-27 16:00:30 发布