Thursday, July 26, 2018

Leetcode 114: Flatten binary tree to linked list

July 26, 2018

Introduction


It is a medium level tree algorithm, I spent over 30 minutes to struggle to write the code. I believed that I did write some code in June but I never tried the solution on the online judge. This time I really had difficult time to figure out the solution.


My practice 


I finally calmed down. I tried to write most simple solution as possible. I did look at the result, it is preorder traversal to output all the nodes in the binary tree. All I have to do is to take care of the current node. If there is a previous node, previous node's right child is current node; the current node's left child will be null pointer.

Here is my C# practice.


No comments:

Post a Comment