solution to flatten a binary tree to a linked list