Monday, February 8, 2016

Leetcode 331: Verify Preorder serialization of a Binary Tree

 Feb. 8, 2016

Serialization of a binary tree, great algorithm to review.

331. Verify Preorder serialization of a Binary Tree
One way to serialize a binary tree is to use pre-oder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #.
     _9_
    /   \
   3     2
  / \   / \
 4   1  #  6
/ \ / \   / \
# # # #   # #

For example, the above binary tree can be serialized to the string "9,3,4,#,#,1,#,#,2,#,6,#,#", where# represents a null node.

idea: Use stack


Here is the blog she starts to read.

  http://bookshadow.com/leetcode/

  https://www.hrwhisper.me/leetcode-algorithm-solution/

  http://www.cnblogs.com/grandyang/p/4606334.html

  http://www.cnblogs.com/EdwardLiu/tag/Leetcode/

 To be continued. 

No comments:

Post a Comment