• 34.1%

Given a binary tree, flatten it to a linked list in-place.

Hints:

If you notice carefully in the flattened tree, each node’s right child points to the next node of a pre-order traversal.

Share my simple NON-recursive solution, O(1) space complexity!

https://discuss.leetcode.com/topic/3995/share-my-simple-non-recursive-solution-o-1-space-complexity

Share my simple NON-recursive solution, O(1) space complexity!

https://discuss.leetcode.com/topic/14481/8ms-non-recursive-no-stack-c-solution

8ms, Non-recursive, No stack, C++ solution

https://discuss.leetcode.com/topic/19087/my-recursive-solution-is-easy-and-clean

My recursive solution is easy and clean!

https://discuss.leetcode.com/topic/9933/16-lines-iterative-c-solution

16 lines iterative c++ solution

Inspired by Morris traversal.

https://discuss.leetcode.com/topic/10606/an-inorder-python-solution

An inorder python solution

The idea is very simple. Suppose n is the current visiting node, and p is the previous node of preorder traversal to n.right.

We just need to do the inorder replacement:

n.left -> NULL

n.right - > n.left

p->right -> n.right

https://discuss.leetcode.com/topic/11444/my-short-post-order-traversal-java-solution-for-share

My short post order traversal Java solution for share

https://discuss.leetcode.com/topic/9936/straightforward-java-solution

Straightforward Java Solution

This solution is based on recursion. We simply flatten left and right subtree and paste each sublist to the right child of the root. (don’t forget to set left child to null)

3ms, 4.67%, September 25, 2016

https://discuss.leetcode.com/topic/5783/accepted-simple-java-solution-iterative