Leetcode 297. Serialize and Deserialize Binary Tree
https://leetcode.com/problems/serialize-and-deserialize-binary-tree/
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.
Example:
You may serialize the following tree:
1
/ \
2 3
/ \
4 5
as "[1,2,3,null,null,4,5]"
Clarification: The above format is the same as how LeetCode 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.
- 构造和解析二叉树。学习python function用法。
- https://leetcode.com/problems/serialize-and-deserialize-binary-tree/discuss/74259/Recursive-preorder-Python-and-C%2B%2B-O(n)
- Built-in Functions — Python 3.7.4 documentation
- https://docs.python.org/3/library/functions.html?highlight=iter#iter
iter(object[, sentinel])- Return an iterator object. The first argument is interpreted very differently depending on the presence of the second argument. Without a second argument, object must be a collection object which supports the iteration protocol (the
__iter__()method), or it must support the sequence protocol (the__getitem__()method with integer arguments starting at0). If it does not support either of those protocols,TypeErroris raised. If the second argument, sentinel, is given, then object must be a callable object. The iterator created in this case will call object with no arguments for each call to its__next__()method; if the value returned is equal to sentinel,StopIterationwill be raised, otherwise the value will be returned.
- https://docs.python.org/3/library/functions.html#next
next(iterator[, default])- Retrieve the next item from the iterator by calling its
__next__()method. If default is given, it is returned if the iterator is exhausted, otherwiseStopIterationis raised.
- https://docs.python.org/3.7/library/stdtypes.html#str.split
str.split(sep=None, maxsplit=-1)- Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most
maxsplit+1elements). If maxsplit is not specified or-1, then there is no limit on the number of splits (all possible splits are made).
- https://docs.python.org/3/library/functions.html?highlight=iter#iter
Leetcode 297. Serialize and Deserialize Binary Tree的更多相关文章
- [leetcode]297. Serialize and Deserialize Binary Tree 序列化与反序列化二叉树
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- [LeetCode] 297. Serialize and Deserialize Binary Tree 二叉树的序列化和反序列化
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- [leetcode]297. Serialize and Deserialize Binary Tree一般二叉树的编解码
由于一般的前序遍历不能唯一的还原出原本你的二叉树,所以要改变一下: 记录二叉树的结构信息,也就是空节点用符号表示 一般的前序遍历只是记录了节点的前后顺序,通过记录空节点,每一层的结构就可以记录下来 解 ...
- 【LeetCode】297. Serialize and Deserialize Binary Tree 解题报告(Python)
[LeetCode]297. Serialize and Deserialize Binary Tree 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode ...
- LC 297 Serialize and Deserialize Binary Tree
问题: Serialize and Deserialize Binary Tree 描述: Serialization is the process of converting a data stru ...
- LeetCode OJ 297. Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- 【LeetCode】297. Serialize and Deserialize Binary Tree
二叉树的序列化与反序列化. 如果使用string作为媒介来存储,传递序列化结果的话,会给反序列话带来很多不方便. 这里学会了使用 sstream 中的 输入流'istringstream' 和 输出流 ...
- 297. Serialize and Deserialize Binary Tree
题目: Serialization is the process of converting a data structure or object into a sequence of bits so ...
- 297. Serialize and Deserialize Binary Tree *HARD*
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
随机推荐
- JDK1.8 LocalDate 使用方式;LocalDate 封装Util,LocalDate工具类(三)
未完待续 ........ 前言: 大企鹅的日常分享,第三步,最近一直在想策略设计模式和工厂模式结合优化ifelse的写法,看了很多资料,终于写出了自己要写的东西,在这段时间里,也有求助小伙伴,但是, ...
- 12-cmake语法-内部变量-系统信息
系统信息 CMAKE_MAJOR_VERSION CMAKE 主版本号,比如 2.4.6 中的 2 CMAKE_MINOR_VERSION CMAKE 次版本号,比如 2.4.6 中的 4 CMAKE ...
- GIL全局解释器锁及协程
GIL全局解释器锁 1.什么是GIL全局解释器锁 GIL本质是一把互斥锁,相当于执行权限,每个进程内都会存在一把GIL同一进程内的多线程,必须抢到GIL之后才能使用Cpython解释器来执行自己的代码 ...
- LeetCode 1213. Intersection of Three Sorted Arrays
原题链接在这里:https://leetcode.com/problems/intersection-of-three-sorted-arrays/ 题目: Given three integer a ...
- Dijkstra单源点最短路径算法
学习参考: Dijkstra算法(单源最短路径) 最短路径—Dijkstra算法和Floyd算法 使用的图结构: 邻接矩阵: -1 20 -1 25 80-1 -1 40 -1 -1-1 -1 -1 ...
- 洛谷P1531 I Hate It题解
题目背景 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 题目描述 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的 ...
- bind 安装 和配置(master/slave)
一,软件安装 #sudo yum -y install bind 二,配置 # vi /etc/named.conf // // named.conf // // Provided by Red H ...
- Azure DevOps Server (TFS) 修改Git文件大小限制
签入Git的所有文件将永远保留在存储库中,限制大文件签入到代码库,可以增加磁盘使用效率,提高系统备份还原等日常维护的效率. 通过下面的设置,团队项目管理员可以阻止超过特定大小的文件进入存储库.如果推送 ...
- 【Python开发】anaconda3 安装python包
环境说明 电脑配置:win7 64位 安装版本:anaconda3 Python 3.6 参考链接 http://python.jobbole.com/86236/ (链接中有一个小点介绍了如何加速包 ...
- 《Linux就该这么学》培训笔记_ch04_Vim编辑器与Shell命令脚本
<Linux就该这么学>培训笔记_ch04_Vim编辑器与Shell命令脚本 文章最后会post上书本的笔记照片. 文章主要内容: Vim编辑器 Shell脚本 流程控制语句 if语句 f ...