题目:

题解:
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def countNodes(self, root: Optional[TreeNode]) -> int:
if root==None:
return 0
return self.countNodes(root.left)+self.countNodes(root.right)+1
![[C++][ProtoBuf][初识ProtoBuf]详细讲解](https://i-blog.csdnimg.cn/direct/b74119537f7a4402ad258e4b253a28d9.png)

















