My simple C++ code

  • 0
    class Solution {
        int minDepth(TreeNode *root) {
            return dfs(root,0);
        int dfs(TreeNode *noot,int depth=0){
        if (noot==NULL)
            return 0;
        if (noot->right==NULL && noot->left==NULL){
            return depth;
        if (noot->right==NULL && noot->left!=NULL)
            return dfs(noot->left,++depth);
        if (noot->right!=NULL && noot->left==NULL)
            return dfs(noot->right,++depth);
            return min(dfs(noot->left,depth),dfs(noot->right,depth));

Log in to reply

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