C# DFS solution


  • 1
    L
        public int FindSecondMinimumValue(TreeNode root) {
            int[] liaValue = new int[] { root.val, -1};
            helper( root, liaValue );
            return liaValue[1];
        }
        
        private void helper( TreeNode root, int[] piaValue ) {
            if ( root != null && ( piaValue[1] == -1 || root.val < piaValue[1]))  {
               if ( root.val != piaValue[0] ) 
                   piaValue[1] = root.val;
                
                helper( root.left, piaValue );
                helper( root.right, piaValue );
        
            }
        }
    

Log in to reply
 

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