We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2106059 commit 2f087a5Copy full SHA for 2f087a5
check_full_binary_tree.py
@@ -0,0 +1,29 @@
1
+"""
2
+Definition of TreeNode:
3
+class TreeNode:
4
+ def __init__(self, val):
5
+ self.val = val
6
+ self.left, self.right = None, None
7
8
+
9
+class Solution:
10
+ """
11
+ @param root: the given tree
12
+ @return: Whether it is a full tree
13
14
+ def isFullTree(self, root):
15
+ # write your code here
16
+ if not root:
17
+ return None
18
+ if (root.left == None) and (root.right == None): # 都为空的话没事
19
+ return True
20
+ elif (root.left != None) and (root.right != None): # 需要递归分别检查左右子树
21
+ is_full = self.isFullTree(root.left)
22
+ if not is_full:
23
+ return False
24
+ is_full = self.isFullTree(root.right)
25
+ return is_full
26
+ else:
27
28
29
+# medium: https://www.lintcode.com/problem/check-full-binary-tree
0 commit comments