Skip to content

Latest commit

 

History

History
13 lines (12 loc) · 236 Bytes

File metadata and controls

13 lines (12 loc) · 236 Bytes
  • 左右子树深度较大者加 1 即为最大深度
class Solution {
 public:
  int maxDepth(TreeNode* root) {
    if (!root) {
      return 0;
    }
    return max(maxDepth(root->left), maxDepth(root->right)) + 1;
  }
};