以下代码实现了二叉树的深度优先搜索(DFS),并统计了叶子节点的数量。横线上应填写( )。
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def count_leaf_nodes(root): if root is None: return 0 stack = [] stack.append(root) count = 0 while stack: node = stack.pop() if node.left is None and node.right is None: count += 1 if node.right: stack.append(node.right) if node.left: _______________________ return count