代码如下:

class Solution:
    def maxDepth(self , root: TreeNode) -> int:
        if not root:
            return 0
        
        left = self.maxDepth(root.left)
        right = self.maxDepth(root.right)
        
        return max(left + 1, right + 1)