二叉树的最小深度

题目:计算二叉树的最小深度。最小深度定义为从root到叶子节点的最小路径。

        static int minDepth(TreeNode *root)
        {
            if(!root->left&&!root->right)
                return 1;
            int L,R;
            L=R=INT_MAX;
            if(root->left)
                L=minDepth(root->left );
            if(root->right)
                R=minDepth(root->right);
            return min(L,R)+1;    
        }
        int MinDepth(TreeNode *root)
        {
            if(!root)
                return 0;
            return minDepth(root);    
        }



你可能感兴趣的:(二叉树的最小深度)