Leetcode: Maximum Depth of Binary Tree

来源:互联网 发布:淘宝旺旺mac版 编辑:程序博客网 时间:2024/06/13 09:54

http://oj.leetcode.com/problems/maximum-depth-of-binary-tree/


/** * Definition for binary tree * struct TreeNode { *     int val; *     TreeNode *left; *     TreeNode *right; *     TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */#include<algorithm>using namespace std;class Solution {public:    int maxDepth(TreeNode *root) {        // Start typing your C/C++ solution below        // DO NOT write int main() function        if(root==NULL) return 0;        return max(maxDepth(root->left),maxDepth(root->right))+1;    }};


原创粉丝点击