104. Maximum Depth of Binary Tree

来源:互联网 发布:java微信商城开源 编辑:程序博客网 时间:2024/06/05 09:54

Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

int maxDepth(struct TreeNode* root) {int LH = 0, RH = 0, H = 0;if (!root)return 0;else{LH = maxDepth(root->left);RH = maxDepth(root->right);H = ((LH > RH) ? LH : RH);return H + 1;}}


0 0
原创粉丝点击