题解 | #判断是不是完全二叉树#

判断是不是完全二叉树

https://www.nowcoder.com/practice/8daa4dff9e36409abba2adbe413d6fae

from re import T
# 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
        if root is None:
            return False
        qe = [root]
        flag = True
        while len(qe)>0:
            this = qe.pop(0)
            if this.left is not None and this.right is not None:
                if flag==False:
                    return False
                qe.append(this.left)
                qe.append(this.right)
            elif this.left is not None and this.right is None:
                if flag==False:
                    return False
                flag = False
                qe.append(this.left)
            elif this.right is not None and this.left is None:
                return False
            else:
                flag = False
        
        return True

全部评论

相关推荐

面向对象的火龙果很爱...:去吃一顿炸鸡就走
点赞 评论 收藏
分享
白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务