class Solution(object):
# 递归思路:
# (1)如果二叉树为空,节点个数为0
# (2)如果二叉树不为空,二叉树节点个数 = 左子树节点个数 + 右子树节点个数 + 1
def countNodes(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if not root:
return 0
return self.countNodes(root.left) + self.countNodes(root.right) + 1