偶遇串行化 Serializer

本文讲述了作者在LeetCode上遇到的关于二叉树串行化和解串行化的难题,探讨了如何使用C++实现这一功能,包括处理NULL指针、使用deque和string等数据结构,以及解决解串行化的递归问题。通过实践,作者实现了高效的串行化和解串行化算法,并提供了完整的程序代码。
摘要由CSDN通过智能技术生成

偶遇串行化 Serializer

  • MD doCumEnT: 3/13/2016 6:06:17 AM by Jimbowhy

我其实是挺理解老外大胡子编程人士为何爱用“f**king code”来描述那种状态,因为有时候眼手一起码上了劲,就会真有那种感觉的啊! - by Jimbowhy, 3/13/2016 7:55:10 AM

偶遇串行化

玩 LeetCode 的过程中,无意打开了模拟面试的功能 Mock Interview,出现一条60分钟的试题,喔!串行化,作为一个编程领域必备技术,串行化的功能最能体现威力的就有远程对象传输,也就是说通过网络,将本机运程的程序对象发送给另一个正在运行的程序,是不是很棒!作为 MFC 六大核心机制之一的串行化,也用于 MFC 体系中的文件存储,总之串行化和解串行是令我兴奋的技术之一。今天就要来 LeetCode 解一解串行化的题目,原题内容:

No. 297 Serialize and Deserialize Binary Tree My Submissions Question
Total Accepted: 15172 Total Submissions: 56198 Difficulty: Hard

Remaining time: 38 minutes, 29 seconds.
Serialize and Deserialize Binary Tree
Difficulty: Hard

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 serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.

For example, you may serialize the following tree

    1
   / \
  2   3
     / \
    4   5

as “[1,2,3,null,null,4,5]”, just the same as how LeetCode OJ serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.
Note: Do not use class member/global/static variables to store states. Your serialize and deserialize algorithms should be stateless.

Credits:
Special thanks to @Louis1992 for adding this problem and creating all test cases.

题目大意是,提供一个二叉树对象,实现它的串行化与解串行。边带之前的通配符试题,还有 Cross Self 等等有趣的题目,在 LeetCode 上玩的这几个星期确实让我过足了瘾!之前还用关系 Forth、Mathematica图像处理的文章未完成,做完 LeetCode 这道题就要暂停一阵了。

还有CSDN的问答,动不却就封,太不近情理了,我连因为什么原因被封的都不知道!

编码过程

这道同样是 Hard 的题目花了不少时间,借此机会熟习了一翻C++的一些常用基础类,包含用 string 来处理二进制数据,用 deque 的双向堆栈结构来处理解串行遇到的问题。deque和vector还有list组成了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值