958. 二叉树的完全性检验
发布日期:2021-05-06 11:08:02 浏览次数:25 分类:技术文章

本文共 568 字,大约阅读时间需要 1 分钟。

在这里插入图片描述

在这里插入图片描述

class Solution(object):    def isCompleteTree(self, root):        res=[root]        flag=0        while res:            tmp=res.pop(0)            if tmp.left:                res.append(tmp.left)            if tmp.right:                res.append(tmp.right)            if tmp.right and not tmp.left:                return False            if flag:                if tmp.left or tmp.right:                    return False            #左右节点都没有,或者只有左节点            if (tmp.left and not tmp.right) or (not tmp.left and not tmp.right):                flag=1        return True
上一篇:98. 验证二叉搜索树
下一篇:牛客——最长公共子序列

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2025年04月07日 14时58分22秒