一棵树上的叶子节点个数

    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

 

你可能感兴趣的:(一棵树上的叶子节点个数)