Short simple Python
My t[a] tells the number of trees with root value a. The 1 is for making a leaf (there\'s one way to make a leaf with that value), the sum is for non-leaves (go
My `t[a]` tells the number of trees with root value `a`. The `1` is for making a leaf (there\'s one way to make a leaf with that value), the `sum` is for non-leaves (go over every possible left child value `b`).\n\n    def numFactoredBinaryTrees(self, A):\n        t = {}\n        for a in sorted(A):\n            t[a] = 1 + sum(t[b] * t.get(a/b, 0) for b in A if b < a)\n        return sum(t.values()) % (10**9 + 7)\n
[]