def numWays(self, n, k):
return 0 if n < 1 else sum(reduce(lambda F, i: [(k-1)*(F+F), F], xrange(1, n), [k, 0]))
Nice. Could use sum(F) and n and, though (and _ and n-1 are clearer):
return n and sum(reduce(lambda F, _: [(k-1)*sum(F), F], xrange(n-1), [k, 0]))
Granted, the n and makes it less clear :-)
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.