Python, whats wrong with generators?


  • 0
    V

    it says Line 40: Exception: Type <type 'generator'>: Not implemented even though I turn generator into list

    `class Solution(object):

    def binaryTreePaths(self, root):
        """
        :type root: TreeNode
        :rtype: List[str]
        """
        return list(self.generate(root, ""))
        
    def generate(self, root, s):
        if not root:
            yield ""
            return
        if not root.left and not root.right:
            s += str(root.val)
            yield s
            return
        yield self.generate(root.left, s + str(root.val) + "->")
        yield self.generate(root.right, s + str(root.val) + "->")`

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.