1. 程式人生 > >一棵樹上的葉子節點個數

一棵樹上的葉子節點個數

    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