class Solution(object):
def tribonacci(self, n):
if n==0:
return 0
if n==1:
return 1
if n==2:
return 1
return tribonacci(n-1)+tribonacci(n-2)+tribonacci(n-3)
会报错
global name 'tribonacci' is not defined
解决方法
class Solution(object):
def tribonacci(self, n):
if n==0:
return 0
if n==1:
return 1
if n==2:
return 1
#return tribonacci(n-1)+tribonacci(n-2)+tribonacci(n-3)
return self.tribonacci(n-1)+self.tribonacci(n-2)+self.tribonacci(n-3)