104. Maximum Depth of Binary Tree
最後に+1が必要だった。問題に二分木が書いてあって再帰をすぐに適応できた。
class Solution { public: int maxDepth(TreeNode* root) { if(!root){ return 0; } return max(maxDepth(root->left), maxDepth(root->right))+1; } };
最後に+1が必要だった。問題に二分木が書いてあって再帰をすぐに適応できた。
class Solution { public: int maxDepth(TreeNode* root) { if(!root){ return 0; } return max(maxDepth(root->left), maxDepth(root->right))+1; } };