当前位置:网站首页>判断是否平衡二叉树
判断是否平衡二叉树
2022-07-21 11:30:00 【咕噜咕噜day】
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param root TreeNode类
# @return bool布尔型
#
class Solution:
def isCompleteTree(self , root: TreeNode) -> bool:
# write code here
# 判断完全二叉树:层序遍历,设置flag 判断当前节点是否存在
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
边栏推荐
猜你喜欢
Minimalist investment notes - be a rich yourself
PAM4科普
声学术语记录
3.3 application of stack and queue
2.3线性表的链式表示(1)
Json 格式的接口测试该怎么做?
Xiangtan party and government delegation visited Qilin Xin'an for investigation
Yan Weimin Chapter II answers to exercises after class
即时零售三国杀:美团补仓、阿里协同、京东引流
蚂蚁安全实验室10篇论文被CCF-A类顶会收录,探索从算法角度实现AI可信
随机推荐
idea报错求助!!!!
【CCF CSP】201512-1数位之和
Scala函数的柯里化
Excel实操笔记1
严蔚敏第二章课后习题答案
【黑马早报】苏宁张康阳败诉,被“追债”17亿;恒驰总裁称恒驰大卖已成定局;iPhone14ProMax镜头激凸严重;微信支持全屏输入...
When servlet writes webapp, filter interception is used to realize login verification
【CCF CSP】201903-1小中大
Hutool tool classes and tool methods
[CCF CSP] 201509-1 sequence segmentation
Yan Weimin Chapter II after class exercises (2.29-2.38)
MONAI Label 安装流程及使用攻略
10 papers of ant security laboratory were included by ccf-a top meeting to explore the realization of AI credibility from the perspective of algorithm
2.3 chain representation of linear table (1)
薅羊毛的最高境界,解放你的双手
BUUCTF-pwn[1]
Local inner class
Natural language Processing in tensorflow quizs on Coursera
3.1 stack
极简投资笔记-做一个富有的你自己