@bacon Thanks dude, I just abandon the recursive part and rewrite it into purely awkward iterative version. lol

class Solution {
public TreeNode trimBST(TreeNode root, int L, int R) {
if (root == null) {
return root;
}
while (root.val < L || root.val > R) {
if (root.val < L) {
root = root.right;
}
if (root.val > R) {
root = root.left;
}
}
TreeNode dummy = root;
while (dummy != null) {
while (dummy.left != null && dummy.left.val < L) {
dummy.left = dummy.left.right;
}
dummy = dummy.left;
}
dummy = root;
while (dummy != null) {
while (dummy.right != null && dummy.right.val > R) {
dummy.right = dummy.right.left;
}
dummy = dummy.right;
}
return root;
}
}