My lambda python solution

  • 0

    The idea is based on the recursion relation:

    a_{n+1} = sum( [a_{n}, a_{n-1}, ..., a_{0}] x [a_{0}, a_{1}, ..., a_{n}] )


    class Solution(object):
    	def numTrees(self, n):
    		lst = [1] #a_{0}=1
    		for i in range(n):
    			lst.append(sum(map(lambda x, y : x * y, lst, reversed(lst))));
    		return lst[-1]

Log in to reply

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