leetcode 104. 二叉树的最大深度
/** * Definition for a binary tree node. * 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; } int left_depth = maxDepth(root->left)+1; int right_depth = maxDepth(root->right)+1; return max(left_depth,right_depth); } };
以大多数人努力程度之低,根本轮不到去拼天赋~