public int count = 0;
public int secondLargest(TreeNode root) {

    if (root == null || count >= 2) {
        return;
    }
    secondLargest(root.right) ;
    count++;
    if (count == 2) {
        System.out.println(root.val);
        return;
    }
    secondLargest(root.left);

    }
}

results matching ""

    No results matching ""