标签:style class blog code color for
题目:输入一棵二叉树的根节点,求该树的深度
题解分析:
二叉树具有天然的递归性,首先应该想递归解法
/** * 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 == NULL) return 0; return max(maxDepth(root->left), maxDepth(root->right)) + 1; } };
剑指offer (39) 二叉树深度,布布扣,bubuko.com
标签:style class blog code color for
原文地址:http://www.cnblogs.com/wwwjieo0/p/3810163.html