leetcode222. Count Complete Tree Nodes

class Solution:
    def __init__(self):
        self.count = 0
        
    def countNodes(self, root: TreeNode) -> int:
        self.helper(root)
        return self.count
        
    def helper(self, root):
        if root is None:
            return
        self.count += 1
        self.countNodes(root.left)
        self.countNodes(root.right)
发布了227 篇原创文章 · 获赞 13 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/weixin_36149892/article/details/98113487