update problem5 solution: recursive visiting tree node