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

判断是不是完全二叉树

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

class Solution:
    def isCompleteTree(self , root: TreeNode) -> bool:
        # write code here
        list_temp2=[]#存结点

        now=root
        while now!=None:
            list_temp2.append(now.left) 
        
            list_temp2.append(now.right) 

            if list_temp2:
                now=list_temp2.pop(0)
                if now==None:
                    for li in list_temp2:
                        if li!=None:
                            return False
            else:
                now=None

        return True

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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