Congratulation! Your runtime beats 99.94% of cpp submissions.


  • -2
    C
    class Solution {
        void _innerDepth(TreeNode* root,int depth){
            if(m <= depth || !root){
                return;
            }
            if(!root->left && !root->right && m > depth){
                m = depth;
                return;
            }
            
            _innerDepth(root->left,depth + 1);
            _innerDepth(root->right,depth + 1);
        }
        int m;
    public:
        int minDepth(TreeNode* root) {
            if(!root) return 0;
            m = 0xfffffff;
            _innerDepth(root,1);
            
            return m;
        }
    };

Log in to reply
 

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