Easy Java Solution


  • 0
    R
            public int findSecondMinimumValue(TreeNode root) 
            {			
                return getMoreValThanMainNode(root, root);
            }
    
    	private int getMoreValThanMainNode(TreeNode root, TreeNode mainNode) 
    	{		
    		if(root == null) return -1;
    		
    		if(root.val > mainNode.val) return root.val;
    		
    		int left  = getMoreValThanRoot(root.left, mainNode);
    		int right = getMoreValThanRoot(root.right, mainNode);
    		
    		return left > 0 && right > 0 ? Math.min(left, right) : Math.max(left, right);		
    	}

Log in to reply
 

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