public static TreeNode getLCA(TreeNode root, TreeNode p, TreeNode q) {
        if (root == null || p == null || q == null) return null;
        if (root.val > Math.max(p.val, q.val)) {
            return getLCA(root.left, p, q);
        } else if (root.val < Math.min(p.val, q.val)) {
            return getLCA(root.right, p, q);
        } else {
            return root;
        }
    }