当前位置:网站首页>Judge whether it is a complete binary tree
Judge whether it is a complete binary tree
2022-07-22 04:07:00 【Gulu Gulu day】
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
#
# The class name in the code 、 Method name 、 The parameter name has been specified , Do not modify , Return the value specified by the method directly
#
#
# @param root TreeNode class
# @return bool Boolean type
#
class Solution:
def isCompleteTree(self , root: TreeNode) -> bool:
# write code here
# Judging a complete binary tree : Sequence traversal , Set up flag Judge whether the current node exists
if not root:
return
node_lst = []
node_lst.append(root)
flag = False
while node_lst:
layer_node = []
while node_lst:
cur = node_lst.pop(0)
if not cur:
flag = True
else:
if flag:
return False
layer_node.append(cur.left)
layer_node.append(cur.right)
node_lst.extend(layer_node)
return True
边栏推荐
猜你喜欢
团队协作api管理工具除了swagger,还有yapi
CountDownLatch与CyclicBarrier基本原理及区别
xxl-job(2.3.0)分布式任务bean模式,GLUE shell调度实践,源码debug
Top understanding notes of LSTM
What does the residual network solve and why is it effective abstract
一款令我相见恨晚的工具Utools
openfegin/restemplate微服务调用最佳实践总结
minio文件系统8.0.3
3.3 application of stack and queue
Natural language Processing in tensorflow quizs on Coursera
随机推荐
编译php7 指定remi扩展目录和ini的配置目录
Typora使用小手册
【CCF CSP】201412-1门禁系统
12306抢票神器
【CCF CSP】201612-1中间数
Monai label installation process and use strategy
gadget之usb_gadget
2020-2021新技术讲座课程
Thesis reading: ctrl: a conditional transformer language model for controllable generation
【CCF CSP】201409-1相邻数对
2021-03-14-jwolf-temp-note
如何解开和反编译思科cisco的交换机固件
C#程序设计经典教程
重入读写锁ReentrantReadWriteLock特性总结
【CCF CSP】201809-1卖菜
Countdownlatch, cyclicbarrier, semaphore of concurrent programming
Tree model summary
Shell programming - functions
xxl-job(2.3.0)分布式任务bean模式,GLUE shell调度实践,源码debug
使用shell将一个目录的所有文件移动以年月为名的文件夹中