to debug: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = None## 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可## # @param root TreeNode类 # @return bool布尔型#from typing import Tupleclass Solution: def isCompleteTree(self , root: TreeNode) -> bool: depth = 1 choices = [root] def next_loop(choices:List[TreeNode])->Tuple[List[TreeNode],bool]: new_choices = [] null_leaves = 0 for choice in choices: if choice.left is not None: if null_leaves==0: new_choices.append(choice.left) else: return [],False else: null_leaves+=1 if choice.right is not None: if null_leaves==0: new_choices.append(choice.right) else: return [],False else: null_leaves+=1 print(new_choices) return new_choices,True while len(choices)!=0: new_choices,not_all_left = next_loop(choices) if (not not_all_left): return False if len(new_choices)!=0 and len(new_choices)!=2**(depth-1): return False depth+=1 choices = new_choices return True