一棵树上的叶子节点个数

    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

猜你喜欢

转载自blog.csdn.net/weixin_36149892/article/details/83831293
今日推荐