题解 | #判断是不是完全二叉树#
判断是不是完全二叉树
https://www.nowcoder.com/practice/8daa4dff9e36409abba2adbe413d6fae
层次遍历。
class Solution: def isCompleteTree(self , root: TreeNode) -> bool: if not root: return True s = [] s.append(root) flag = False while len(s): for i in range(len(s)): node = s[0] s.pop(0) if not node: flag = True else: if flag: return False s.append(node.left) s.append(node.right) return True