标签:style blog io ar color sp for on div
返回树的深度。
递归:
/** * Definition for binary tree * 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; int l = maxDepth(root -> left); int r = maxDepth(root -> right); return max(l + 1, r + 1); } };
leetcode Maximum Depth of Binary Tree
标签:style blog io ar color sp for on div
原文地址:http://www.cnblogs.com/higerzhang/p/4128650.html