@nychent
Thank you for your reply, the space complexity is related to the height of the tree if the tree is balanced, the height is O(logN), and the worst case is O(n). The same to the iteration method. This is my option if you have some explanations, I am happy to discuss with you.