cpp 1 line solution: recursive method(dfs)


  • 0
    Y
    class Solution {
    public:
        int maxDepth(TreeNode* root) {
            return root ? max(1 + maxDepth(root->left), 1 + maxDepth(root->right)) : 0;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.