still can be improved
online solution
use stack
note only 1 node