题解 | #判断是不是完全二叉树#
判断是不是完全二叉树
https://www.nowcoder.com/practice/8daa4dff9e36409abba2adbe413d6fae
# 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 list_tree = [root] find = False while list_tree: t = [] for i in list_tree: if not find : if i.left != None : t.append(i.left) if i.right != None: t.append(i.right) else: find = True else: if i.right != None: return False find = True else: if i.left != None or i.right != None: return False list_tree = t return True
原始一点点的解法 文章被收录于专栏
尽量不借助面向对象的思想,自己去实习具体过程