My accepted Java Solution


  • 0
    H

    I just traverse the tree and get the second minimum one

    public int findSecondMinimumValue(TreeNode root) {
            List<Integer> num=new ArrayList<>();
            help(root,num);
            Collections.sort(num);
            for(int i:num){
                if(i!=root.val)
                    return i;
            }
            return -1;
        }
        public void help(TreeNode root,List<Integer> list){
            if(root==null)
                return;
            help(root.left,list);
            list.add(root.val);
            help(root.right,list);
        }
    
    

Log in to reply
 

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