LintCode Q163 Unique Binary Search Trees in Python

  • Jinhai ZHOU
  • 2 Minutes
  • 2017年1月8日
1
2
3
4
5
6
7
8
9
10
11
class Solution:
# @paramn n: An integer
# @return: An integer
def numTrees(self, n):
# write your code here
# They are actually catalan numbers
# https://en.wikipedia.org/wiki/Catalan_number
if n < 0:
return
catalan = [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452]
return catalan[n]
知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。