Easy C++ solution


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

Log in to reply
 

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