难度 简单
题目 Leetcode:
The Tribonacci sequence Tn is defined as follows:
T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
Given n, return the value of Tn.
题目解析
图一乐
速度击败100%内存击败97%,笑死
1 class Solution { 2 public: 3 int tribonacci(int n) { 4 if(n==0)return 0; 5 else if(n==1)return 1; 6 else if(n==2)return 1; 7 else if(n==3)return 2; 8 else if(n==4)return 4; 9 else if(n==5)return 7; 10 else if(n==6)return 13; 11 else if(n==7)return 24; 12 else if(n==8)return 44; 13 else if(n==9)return 81; 14 else if(n==10)return 149; 15 else if(n==11)return 274; 16 else if(n==12)return 504; 17 else if(n==13)return 927; 18 else if(n==14)return 1705; 19 else if(n==15)return 3136; 20 else if(n==16)return 5768; 21 else if(n==17)return 10609; 22 else if(n==18)return 19513; 23 else if(n==19)return 35890; 24 else if(n==20)return 66012; 25 else if(n==21)return 121415; 26 else if(n==22)return 223317; 27 else if(n==23)return 410744; 28 else if(n==24)return 755476; 29 else if(n==25)return 1389537; 30 else if(n==26)return 2555757; 31 else if(n==27)return 4700770; 32 else if(n==28)return 8646064; 33 else if(n==29)return 15902591; 34 else if(n==30)return 29249425; 35 else if(n==31)return 53798080; 36 else if(n==32)return 98950096; 37 else if(n==33)return 181997601; 38 else if(n==34)return 334745777; 39 else if(n==35)return 615693474; 40 else if(n==36)return 1132436852; 41 else if(n==37)return 2082876103; 42 return 0; 43 } 44 };