当前位置:网站首页>【leetcode】331. 验证二叉树的前序序列化
【leetcode】331. 验证二叉树的前序序列化
2022-06-26 15:21:00 【liiiiiiiiiiiiike】
题目详见 331. 验证二叉树的前序序列化
解题思路:
9 # # 1
- slots表示一个槽位‘#’,空树,需要一个槽位。
- split后,遍历,如果slots == 0,说明没有槽位了,此时已经满了,但是又有新的元素,所以返回false
- i==‘#’,slots -= 1槽位减一, i != ‘#’ slots +=1
class Solution:
def isValidSerialization(self, preorder: str) -> bool:
# 9 # # 1
slots = 1
for i in preorder.split(','):
if slots == 0:
return False
if i == '#':
slots -= 1
else:
slots += 1
return slots == 0
边栏推荐
- Evaluate:huggingface评价指标模块入门详细介绍
- 有Cmake的工程交叉编译到链接时报错找不到.so动态库文件
- 【微信小程序】事件绑定,你搞懂了吗?
- 【TcaplusDB知识库】TcaplusDB单据受理-事务执行介绍
- 【小程序实战系列】小程序框架 页面注册 生命周期 介绍
- Comparative analysis of restcloud ETL and kettle
- 2022 Beijing Shijingshan District specializes in the application process for special new small and medium-sized enterprises, with a subsidy of 100000-200000 yuan
- Audio and video learning (I) -- PTZ control principle
- 【TcaplusDB知识库】TcaplusDB常规单据介绍
- 【ceph】CephFS 内部实现(三):快照
猜你喜欢
随机推荐
MongoDB系列之Window环境部署配置
功能:crypto-js加密解密
Vsomeip3 dual computer communication file configuration
Evaluate:huggingface detailed introduction to the evaluation index module
Unity C # e-learning (VIII) -- www
Applet: uniapp solves vendor JS is too large
Database - sequence
Unity C# 网络学习(八)——WWW
Inaccurate data accuracy in ETL process
Cache page keepalive use in Vue
【毕业季·进击的技术er】 什么是微信小程序,带你推开小程序的大门
2022 Beijing Shijingshan District specializes in the application process for special new small and medium-sized enterprises, with a subsidy of 100000-200000 yuan
【SNMP】snmp trap 介绍、安装、命令|Trap的发送与接收代码实现
10 minutes to understand bim+gis fusion, common BIM data formats and characteristics
学习内存屏障
【TcaplusDB知识库】TcaplusDB运维单据介绍
Using restcloud ETL shell component to schedule dataX offline tasks
HW安全响应
Database - integrity constraints
5 figures illustrate the container network








![[wechat applet] event binding, do you understand?](/img/83/6242e972538d0423fd4155140bb521.png)