Maximum Depth of Binary Tree

 

CREATED TIME: Jan 20, 2020 10:07 PM UPDATED TIME: Jan 20, 2020 10:08 PM 난이도: Easy

/** * 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 res = max( maxDepth(root->left), maxDepth(root->right) ) + 1; return res; } };