Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.
Design an algorithm to encode and decode BST.
leetcode 449 : Serialize and Deserialize BST
刚开始觉得怎么和271类似,于是呼写了个一毛一样的,居然过了。
|
|
不小心点开了discuss里一个用c++的高票,果然牛逼啊。基本思路依旧是preorder遍历,但是inline,memcpy的应用再加上用4个char来代替string,以及利用binary serch tree 的特性免去了对string的解析和内存的浪费,按照这个思路重新写一下。
|
|
又一次感受到了C++和C对底层性能的高效应用以及编译器的强大。