[Minimum Depth of Binary Tree] [C++] - 1 Line Solution


  • 1
    class Solution {
    public:
        int minDepth(TreeNode* r) {
            return !r ? 0 : (!r->left && !r->right) ? 1 : 1 + min((r->left ? minDepth(r->left) : INT_MAX), (r->right ? minDepth(r->right) : INT_MAX)); 
        }
    };
    

Log in to reply
 

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