Skip to content

Commit 2f087a5

Browse files
authored
Create check_full_binary_tree.py
1 parent 2106059 commit 2f087a5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

check_full_binary_tree.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
return False
28+
29+
# medium: https://www.lintcode.com/problem/check-full-binary-tree

0 commit comments

Comments
 (0)