![[LeetCode] 104、二叉树的最大深度](http://pic.xiahunao.cn/yaotu/[LeetCode] 104、二叉树的最大深度)
题目描述给定一个二叉树找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。说明: 叶子节点是指没有子节点的节点。参考代码简单题/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */classSolution{public:intmaxDepth(TreeNode*root){if(!root){return0;}intleftDepthmaxDepth(root-left);intrightDepthmaxDepth(root-right);returnmax(leftDepth,rightDepth)1;// 1 是关键}};