[leetcode] Maximum Depth of Binary Tree

来源:互联网 发布:网络银商最重的判刑 编辑:程序博客网 时间:2024/04/30 09:32

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.

class Solution {public:    int maxDepth(TreeNode *root) {// Start typing your C/C++ solution below// DO NOT write int main() functionint left,right;if(root==NULL)return 0;return (left=maxDepth(root->left))>(right=maxDepth(root->right))?left+1:right+1;}};

求二叉树的高

原创粉丝点击