题目如下:

The Tribonacci sequence Tn is defined as follows:

T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2for n >= 0.

Given n, return the value of Tn.

Example 1:

Input: n = 4
Output: 4
Explanation:
T_3 = 0 + 1 + 1 = 2
T_4 = 1 + 1 + 2 = 4

Example 2:

Input: n = 25
Output: 1389537

Constraints:

  • 0 <= n <= 37
  • The answer is guaranteed to fit within a 32-bit integer, ie. answer <= 2^31 - 1.

解题思路:动态规划入门级的题目。

代码如下:

class Solution(object):
fib_list = []
def tribonacci(self, n):
"""
:type n: int
:rtype: int
"""
f = [0,1,1]
if len(self.fib_list) == 0:
for i in range(0,38):
if i <= 2:
self.fib_list.append(f[i])
continue
self.fib_list.append(self.fib_list[-1] + self.fib_list[-2] + self.fib_list[-3]) return self.fib_list[n]

【leetcode】1137. N-th Tribonacci Number的更多相关文章

  1. 【LeetCode】287. Find the Duplicate Number

    Difficulty:medium  More:[目录]LeetCode Java实现 Description Given an array nums containing n + 1 integer ...

  2. 【LeetCode】1150. Check If a Number Is Majority Element in a Sorted Array 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 二分查找 日期 题目地址:https://lee ...

  3. 【LeetCode】1137. N-th Tribonacci Number 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetc ...

  4. 【LeetCode】171. Excel Sheet Column Number 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 解题方法 Java解法 Python解法 日期 [LeetCode] 题 ...

  5. 【LeetCode】476. 数字的补数 Number Complement

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:Leetcode, 力扣,476, 补数,二进制,Pyth ...

  6. 【LeetCode】287. Find the Duplicate Number 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 保存已经访问过的数字 链表成环 二分查找 日期 题目 ...

  7. 【LeetCode】190 & 191 - Reverse Bits & Number of 1 Bits

    190 - Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432615 ...

  8. 【LeetCode】9 & 234 & 206 - Palindrome Number & Palindrome Linked List & Reverse Linked List

    9 - Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Som ...

  9. 【LeetCode】171. Excel Sheet Column Number

    题目: Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, r ...

随机推荐

  1. 阶段3 1.Mybatis_11.Mybatis的缓存_8 mybatis的二级缓存

    二级缓存:             它指的是Mybatis中SqlSessionFactory对象的缓存.由同一个SqlSessionFactory对象创建的SqlSession共享其缓存.      ...

  2. 【FICO系列】SAP FICO 凭证错误:BKPFF$PRDCLN800在FI中达到的项目最大编号

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[FICO系列]SAP FICO 凭证错误:BK ...

  3. python每日一练:0015题

    第 0015 题: 纯文本文件 city.txt为城市信息, 里面的内容(包括花括号)如下所示: { "1" : "上海", "2" : & ...

  4. 20191106 Spring Boot官方文档学习(1-2)

    学习内容相关信息 最新版本:2.2.0 CURRENT GA 官网地址 官方文档地址 单页版文档地址 代码生成网址 2.入门 Spring Boot的主要目标是: 为所有Spring开发提供更快且入门 ...

  5. fastjson @JSONField

    此文来源于:https://blog.51cto.com/xiaok007/2164029 1.作用在FIELD(成员变量上) 注意:1.若属性是私有的,必须有set*方法.否则无法反序列化. pac ...

  6. ThinkPHP目录下面php文件 Access denied. 的问题

    对于这种拒绝访问的报错,从我遇到过的问题总结来讲,可以从几个方向入手: 1. 文件权限. 最容易想到的也是这个 使用命令chmod -R 777 目录名 2. 环境配置.    这个我也是有遇到过的 ...

  7. linux下安装msgpack,yar,phalcon

    安装msgpack扩展 下载:http://pecl.php.net/package/msgpack cd /usr/local tar zxvf msgpack-0.5.5.tgz cd msgpa ...

  8. PHP排序函数sort、rsort、asort、arsort、ksort、krsort

    1.sort函数用于对数组元素值从低到高排序,去除原始索引元素,重新生成0,1,2..的键2.rsort函数用于对数组元素值从高到低排序,去除原始索引元素,重新生成0,1,2..的键3.asort函数 ...

  9. shell学习笔记1---shell编程基础

    Shell是什么? Shell 是一个应用程序,它连接了用户和 Linux 内核,让用户能够更加高效.安全.低成本地使用 Linux 内核,这就是 Shell 的本质. Shell 本身并不是内核的一 ...

  10. [LeetCode] 84. 柱状图中最大的矩形

    题目链接 : https://leetcode-cn.com/problems/largest-rectangle-in-histogram/ 题目描述: 给定 n 个非负整数,用来表示柱状图中各个柱 ...