C# Solution (Beats 98%)


  • 0
    K
        public int MinDepth(TreeNode root) 
        {
            if (root == null)
                return 0;
            return Helper(root);
        }
        
        private int Helper(TreeNode root){
            if (root == null){
                return Int32.MaxValue;
            }
            
            if (root.left == null && root.right == null){
                return 1;
            }
            
            return Math.Min(Helper(root.left), Helper(root.right)) + 1;
        }
    }

Log in to reply
 

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