当前位置:网站首页>LeetCode_1137_第N个泰波那契数
LeetCode_1137_第N个泰波那契数
2022-07-28 17:05:00 【Fitz1318】
题目链接
题目描述
泰波那契序列 Tn 定义如下:
T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0 的条件下 Tn+3 = Tn + Tn+1 + Tn+2
给你整数 n,请返回第 n 个泰波那契数 Tn 的值。
示例 1:
输入:n = 4
输出:4
解释:
T_3 = 0 + 1 + 1 = 2
T_4 = 1 + 1 + 2 = 4
示例 2:
输入:n = 25
输出:1389537
提示:
0 <= n <= 37- 答案保证是一个 32 位整数,即
answer <= 2^31 - 1。
解题思路
AC代码
class Solution {
public int tribonacci(int n) {
if (n == 0) {
return 0;
}
if (n == 1 || n == 2) {
return 1;
}
int[] dp = new int[n + 1];
dp[0] = 0;
dp[1] = 1;
dp[2] = 1;
for (int i = 3; i <= n; i++) {
dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
}
return dp[n];
}
}
边栏推荐
- What skills do you need to master when learning software testing zero foundation?
- 深圳线下报名|StarRocks on AWS:如何对实时数仓进行极速统一分析
- The revenue of Shanghai silicon industry in the first half of the year was 850million yuan, an increase of 30.53% year on year! Various product certifications are accelerating
- .net swagger
- cout.write的学习
- 【译】创意编码之噪音
- 矢量网络分析仪(矢网)组成和原理简介
- Live broadcast starrocks technology insider: low base global dictionary optimization
- 信号源原理简介
- 高德地图实现自定义小蓝点 自定义点标记 绘制多边形/圆形区域 根据地图的移动显示或者隐藏自定义点标记的相关实现
猜你喜欢

TCP/IP详细图解

Tencent Tang Daosheng: open source is a new mode of production and collaboration in the era of industrial Internet

Ue5 gas learning notes 0.2 configuration plug-in

Live broadcast starrocks technology insider: low base global dictionary optimization

SQL Server stuff and for XML path

Composition and principle of vector network analyzer (vector network)

示波器简介

Brief introduction to the principle of spectrometer II

npm 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

NDK 系列(5):JNI 从入门到实践,爆肝万字详解!
随机推荐
Is the training institution of software testing reliable
UE5 GAS 学习笔记8.0参考资料
DC-DC开关电源
MQTT over QUIC:下一代物联网标准协议为消息传输场景注入新动力
Wired: who owns the art of the future? Openai allows dall-e users to commercialize their works. At present
UE5 GAS 学习笔记 1.6 技能Gameplay Ability
Modifier modifier modifier of solidity _;
How to see the future development of software testing?
腾讯汤道生:开源是产业互联网时代新的生产方式和协作模式
VSC writes go, expected 'package' appears, found 'EOF‘
Devops in digital transformation -- flexible cooperation
Five key considerations for network security budget planning in 2023
Mingde biology: no products of the company have been listed in the WHO recommended list
Go's walk library reports an error
高德地图实现自定义小蓝点 自定义点标记 绘制多边形/圆形区域 根据地图的移动显示或者隐藏自定义点标记的相关实现
MySQL advanced mvcc (ultra detailed collation)
Multithreading and high concurrency -- source code analysis AQS principle
GIS数据漫谈(六)— 投影坐标系统
MySQL operation Encyclopedia
矢量网络分析仪(矢网)的校准