一棵二叉树上的叶子节点数

    def getLeaveNodes(self, root, count):
        if root is None:
            return  0
        if root.left is None and root.right is None:
            count += 1
            return count
        left_count = self.getLeaveNodes(root.left, count)
        right_count = self.getLeaveNodes(root.right, count)
        return left_count +  right_count

 

posted @ 2020-11-24 09:06  XXXSANS  阅读(82)  评论(0编辑  收藏  举报