Leetcode 104. 二叉树的最大深度

xiaoxiao2021-02-28  2

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int maxDepth(TreeNode* root) { if(!root) return 0; return 1+max(maxDepth(root->left),maxDepth(root->right)); } };
转载请注明原文地址: https://www.6miu.com/read-1600146.html

最新回复(0)