An easy and short answer of cpp


  • 6
    W
    class Solution {
        public:
        int minDepth(TreeNode* root) {
            if (root ==NULL)
                return 0;
            int l = minDepth(root->left) ;
            int r = minDepth(root->right) ;
            if (l==0 || r==0)
                return l+r+1 ;
            return (l>r?r:l)+1 ;
        }
    };

Log in to reply
 

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