C++ Leetcode 111Minimum Depth of Binary Tree

来源:互联网 发布:视频滚动字幕制作软件 编辑:程序博客网 时间:2024/06/06 20:19

class Solution {public:    int minDepth(TreeNode* root) {        if(root == 0) return 0;        int depth ;        if(root!=0)          {            depth = 1;            int L =   minDepth(root->left);            int R =   minDepth(root->right);            if(L && R)            {                int min = R>L?L:R;                depth += min;            }            else if(L == 0) depth+= R;            else if(R== 0) depth += L;         }         return depth;                    }};


1 0
原创粉丝点击