当前位置:网站首页>【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
边栏推荐
- [graduation season · advanced technology Er] what is a wechat applet, which will help you open the door of the applet
- 【SNMP】snmp trap 介绍、安装、命令|Trap的发送与接收代码实现
- [CEPH] Introduction to cephfs caps
- Analysis of ble packet capturing debugging information
- 【TcaplusDB知识库】TcaplusDB单据受理-创建游戏区介绍
- nanoPi Duo2连接wifi
- 【ceph】cephfs caps简介
- 10 minutes to understand bim+gis fusion, common BIM data formats and characteristics
- 【ceph】CephFS 内部实现(四):MDS是如何启动的?--未消化
- 一键分析硬件/IO/全国网络性能脚本(强推)
猜你喜欢
【TcaplusDB知识库】TcaplusDB数据构造介绍
【问题解决】新版webots纹理等资源文件加载/下载时间过长
小程序:uniapp解决 vendor.js 体积过大的问题
AbortController的使用
[tcapulusdb knowledge base] tcapulusdb OMS business personnel permission introduction
About selenium common. exceptions. Webdriverexception: message: an unknown server side error solution (resolved)
[file] VFS four structs: file, dentry, inode and super_ What is a block? difference? Relationship-- Editing
面试高频 | 你追我赶的Flink双流join
English grammar_ Adjective / adverb Level 3 - original sentence pattern
Notes on brushing questions (19) -- binary tree: modification and construction of binary search tree
随机推荐
在重新格式化时不要删除自定义换行符(Don‘t remove custom line breaks on reformat)
Function: crypto JS encryption and decryption
TCP/IP协议竟然有这么多漏洞?
【ceph】mkdir|mksnap流程源码分析|锁状态切换实例
[graduation season · advanced technology Er] what is a wechat applet, which will help you open the door of the applet
[tcapulusdb knowledge base] tcapulusdb doc acceptance - table creation approval introduction
反射修改final
有Cmake的工程交叉编译到链接时报错找不到.so动态库文件
Evaluate:huggingface评价指标模块入门详细介绍
[CEPH] Lock Notes of cephfs
【TcaplusDB知识库】TcaplusDB数据构造介绍
shell脚本多进程并发写法实例(高阶修炼)
在哪个平台买股票开户安全?求指导
音视频学习(三)——sip协议
【ceph】CephFS 内部实现(四):MDS是如何启动的?--未消化
JS之手写 bind、apply、call
【微信小程序】事件绑定,你搞懂了吗?
【ceph】CEPHFS 内部实现(一):概念篇--未消化
[CEPH] cephfs internal implementation (I): Concept -- undigested
Utilisation d'abortcontroller