@tinalxj12 No, this can't be removed. This is the tricky part of pruning, which means you can avoid traversing right child. I got similar idea.

Queue<Integer> q = new LinkedList<>();
public List<Integer> closestKValues(TreeNode root, double target, int k) {
helper(root, target, k);
List<Integer> res = new ArrayList<>(q);
return res;
}
public void helper(TreeNode node, double target, int k) {
if (node == null) {
return;
}
helper(node.left, target, k);
handle(node, target, k);
}
public void handle(TreeNode node, double target, int k) {
if (q.size() < k) {
q.offer(node.val);
helper(node.right, target, k);
} else {
double v1 = Math.abs(node.val - target);
double v2 = Math.abs(q.peek() - target);
if (v1 < v2) {
q.poll();
q.offer(node.val);
helper(node.right, target, k);
}
}
}