Skip to content

Commit 7579ea7

Browse files
committed
一刷1137
1 parent cc69cbc commit 7579ea7

File tree

6 files changed

+147
-31
lines changed

6 files changed

+147
-31
lines changed

README.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7984,14 +7984,14 @@ TIP: **公众号的微信号是: `jikerizhi`**。__因为众所周知的原因
79847984
//|{doc_base_url}/1136-parallel-courses.adoc[题解]
79857985
//|Hard
79867986
//|
7987-
//
7988-
//|{counter:codes}
7989-
//|{leetcode_base_url}/n-th-tribonacci-number/[1137. N-th Tribonacci Number^]
7990-
//|{source_base_url}/_1137_NThTribonacciNumber.java[Java]
7991-
//|{doc_base_url}/1137-n-th-tribonacci-number.adoc[题解]
7992-
//|Easy
7993-
//|
7994-
//
7987+
7988+
|{counter:codes}
7989+
|{leetcode_base_url}/n-th-tribonacci-number/[1137. N-th Tribonacci Number^]
7990+
|{source_base_url}/_1137_NThTribonacciNumber.java[Java]
7991+
|{doc_base_url}/1137-n-th-tribonacci-number.adoc[题解]
7992+
|Easy
7993+
|
7994+
79957995
//|{counter:codes}
79967996
//|{leetcode_base_url}/alphabet-board-path/[1138. Alphabet Board Path^]
79977997
//|{source_base_url}/_1138_AlphabetBoardPath.java[Java]

docs/0000-27-dynamic-programming.adoc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,71 @@ image::images/dynamic-programming-01.jpeg[{image_attr}]
1515
. 确定遍历顺序
1616
. 举例推导 dp 数组
1717

18+
== 入门题目
19+
20+
21+
. xref:0070-climbing-stairs.adoc[70. Climbing Stairs]
22+
. xref:0509-fibonacci-number.adoc[509. Fibonacci Number]
23+
. xref:1137-n-th-tribonacci-number.adoc[1137. N-th Tribonacci Number]
24+
. xref:0746-min-cost-climbing-stairs.adoc[746. Min Cost Climbing Stairs]
25+
. xref:0198-house-robber.adoc[198. House Robber]
26+
. xref:0213-house-robber-ii.adoc[213. House Robber II]
27+
. xref:0337-house-robber-iii.adoc[337. House Robber III]
28+
. xref:2560-house-robber-iv.adoc[2560. House Robber IV]
29+
. xref:0740-delete-and-earn.adoc[740. Delete and Earn]
30+
. xref:0062-unique-paths.adoc[62. Unique Paths]
31+
. xref:0063-unique-paths-ii.adoc[63. Unique Paths II]
32+
. xref:0980-unique-paths-iii.adoc[980. Unique Paths III]
33+
. xref:0064-minimum-path-sum.adoc[64. Minimum Path Sum]
34+
. xref:0120-triangle.adoc[120. Triangle]
35+
. xref:0931-minimum-falling-path-sum.adoc[931. Minimum Falling Path Sum]
36+
. xref:1289-minimum-falling-path-sum-ii.adoc[1289. Minimum Falling Path Sum II]
37+
. xref:0221-maximal-square.adoc[221. Maximal Square]
38+
. xref:0005-longest-palindromic-substring.adoc[5. Longest Palindromic Substring]
39+
. xref:0139-word-break.adoc[139. Word Break]
40+
. xref:0140-word-break-ii.adoc[140. Word Break II]
41+
. xref:0516-longest-palindromic-subsequence.adoc[516. Longest Palindromic Subsequence]
42+
. xref:1682-longest-palindromic-subsequence-ii.adoc[1682. Longest Palindromic Subsequence II]
43+
. xref:0072-edit-distance.adoc[72. Edit Distance]
44+
. xref:0712-minimum-ascii-delete-sum-for-two-strings.adoc[712. Minimum ASCII Delete Sum for Two Strings]
45+
. xref:0115-distinct-subsequences.adoc[115. Distinct Subsequences]
46+
. xref:0940-distinct-subsequences-ii.adoc[940. Distinct Subsequences II]
47+
. xref:0300-longest-increasing-subsequence.adoc[300. Longest Increasing Subsequence]
48+
. xref:2407-longest-increasing-subsequence-ii.adoc[2407. Longest Increasing Subsequence II]
49+
. xref:0673-number-of-longest-increasing-subsequence.adoc[673. Number of Longest Increasing Subsequence]
50+
. xref:0646-maximum-length-of-pair-chain.adoc[646. Maximum Length of Pair Chain]
51+
. xref:1218-longest-arithmetic-subsequence-of-given-difference.adoc[1218. Longest Arithmetic Subsequence of Given Difference]
52+
. xref:1027-longest-arithmetic-subsequence.adoc[1027. Longest Arithmetic Subsequence]
53+
. xref:0354-russian-doll-envelopes.adoc[354. Russian Doll Envelopes]
54+
. xref:1964-find-the-longest-valid-obstacle-course-at-each-position.adoc[题解]
55+
. xref:1143-longest-common-subsequence.adoc[1143. Longest Common Subsequence]
56+
. xref:1035-uncrossed-lines.adoc[1035. Uncrossed Lines]
57+
. xref:1312-minimum-insertion-steps-to-make-a-string-palindrome.adoc[1312. Minimum Insertion Steps to Make a String Palindrome]
58+
. xref:0309-best-time-to-buy-and-sell-stock-with-cooldown.adoc[309. Best Time to Buy and Sell Stock with Cooldown]
59+
. xref:0714-best-time-to-buy-and-sell-stock-with-transaction-fee.adoc[714. Best Time to Buy and Sell Stock with Transaction Fee]
60+
. xref:0123-best-time-to-buy-and-sell-stock-iii.adoc[123. Best Time to Buy and Sell Stock III]
61+
. xref:0188-best-time-to-buy-and-sell-stock-iv.adoc[188. Best Time to Buy and Sell Stock IV]
62+
. xref:0096-unique-binary-search-trees.adoc[96. Unique Binary Search Trees]
63+
. xref:0095-unique-binary-search-trees-ii.adoc[95. Unique Binary Search Trees II]
64+
. xref:0124-binary-tree-maximum-path-sum.adoc[124. Binary Tree Maximum Path Sum]
65+
. xref:0279-perfect-squares.adoc[279. Perfect Squares]
66+
. xref:0367-valid-perfect-square.adoc[题解]
67+
. xref:0322-coin-change.adoc[322. Coin Change]
68+
. xref:0518-coin-change-ii.adoc[518. Coin Change II]
69+
. xref:0377-combination-sum-iv.adoc[377. Combination Sum IV]
70+
. xref:0474-ones-and-zeroes.adoc[474. Ones and Zeroes]
71+
. xref:2140-solving-questions-with-brainpower.adoc[2140. Solving Questions With Brainpower]
72+
. xref:2466-count-ways-to-build-good-strings.adoc[2466. Count Ways To Build Good Strings]
73+
. xref:0091-decode-ways.adoc[91. Decode Ways]
74+
. xref:0639-decode-ways-ii.adoc[639. Decode Ways II]
75+
. xref:0983-minimum-cost-for-tickets.adoc[983. Minimum Cost For Tickets]
76+
. xref:0790-domino-and-tromino-tiling.adoc[790. Domino and Tromino Tiling]
77+
78+
79+
== 进阶
80+
81+
82+
1883
== 经典题目
1984

2085
. xref:0005-longest-palindromic-substring.adoc[5. Longest Palindromic Substring]

docs/1137-n-th-tribonacci-number.adoc

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,63 @@
11
[#1137-n-th-tribonacci-number]
2-
= 1137. N-th Tribonacci Number
2+
= 1137. 第 N 个泰波那契数
33

4-
{leetcode}/problems/n-th-tribonacci-number/[LeetCode - N-th Tribonacci Number^]
4+
https://leetcode.cn/problems/n-th-tribonacci-number/[LeetCode - 1137. 第 N 个泰波那契数 ^]
55

6-
The Tribonacci sequence T~n~ is defined as follows:
6+
泰波那契序列 T~n~ 定义如下:
77

8-
T~0~ = 0, T~1~ = 1, T~2~ = 1, and T~n+3~ = T~n~ + T~n+1~ + T~n+2~ for n >= 0.
8+
T~0~ = 0, T~1~ = 1, T~2~ = 1, 且在 n >= 0 的条件下 T~n+3~ = T~n~ + T~n+1~ + T~n+2~
99

10-
Given `n`, return the value of T~n~.
10+
给你整数 `n`,请返回第 n 个泰波那契数 T~n~ 的值。
1111

1212

13-
*Example 1:*
1413

15-
[subs="verbatim,quotes,macros"]
16-
----
17-
*Input:* n = 4
18-
*Output:* 4
19-
*Explanation:*
14+
*示例 1:*
15+
16+
....
17+
输入:n = 4
18+
输出:4
19+
解释:
2020
T_3 = 0 + 1 + 1 = 2
2121
T_4 = 1 + 1 + 2 = 4
22-
----
22+
....
2323

24-
*Example 2:*
24+
*示例 2:*
2525

26-
[subs="verbatim,quotes,macros"]
27-
----
28-
*Input:* n = 25
29-
*Output:* 1389537
30-
----
26+
....
27+
输入:n = 25
28+
输出:1389537
29+
....
3130

32-
33-
*Constraints:*
31+
*提示:*
3432

33+
* `+0 <= n <= 37+`
34+
* 答案保证是一个 32 位整数,即 `answer \<= 2^31^ - 1`。
3535

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

37+
== 思路分析
3938

4039

4140
[[src-1137]]
41+
[tabs]
42+
====
43+
一刷::
44+
+
45+
--
4246
[{java_src_attr}]
4347
----
4448
include::{sourcedir}/_1137_NThTribonacciNumber.java[tag=answer]
4549
----
50+
--
51+
52+
// 二刷::
53+
// +
54+
// --
55+
// [{java_src_attr}]
56+
// ----
57+
// include::{sourcedir}/_1137_NThTribonacciNumber_2.java[tag=answer]
58+
// ----
59+
// --
60+
====
61+
4662

63+
== 参考资料

docs/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2356,7 +2356,7 @@ include::1110-delete-nodes-and-return-forest.adoc[leveloffset=+1]
23562356

23572357
// include::1136-parallel-courses.adoc[leveloffset=+1]
23582358

2359-
// include::1137-n-th-tribonacci-number.adoc[leveloffset=+1]
2359+
include::1137-n-th-tribonacci-number.adoc[leveloffset=+1]
23602360

23612361
// include::1138-alphabet-board-path.adoc[leveloffset=+1]
23622362

logbook/202503.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ endif::[]
265265
|{doc_base_url}/0093-restore-ip-addresses.adoc[题解]
266266
|✅ 回溯
267267

268+
|{counter:codes2503}
269+
|{leetcode_base_url}/n-th-tribonacci-number/[1137. 第 N 个泰波那契数^]
270+
|{doc_base_url}/1137-n-th-tribonacci-number.adoc[题解]
271+
|✅ 动态规划
272+
273+
268274
|===
269275
˚
270276
截止目前,本轮练习一共完成 {codes2503} 道题。
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.diguage.algo.leetcode;
2+
3+
public class _1137_NThTribonacciNumber {
4+
// tag::answer[]
5+
6+
/**
7+
* @author D瓜哥 · https://www.diguage.com
8+
* @since 2025-04-16 17:13:08
9+
*/
10+
public int tribonacci(int n) {
11+
if (n <= 0) {
12+
return 0;
13+
}
14+
if (n == 1 || n == 2) {
15+
return 1;
16+
}
17+
int a = 0, b = 1, c = 1;
18+
int result = 0;
19+
for (int i = 3; i <= n; i++) {
20+
result = a + b + c;
21+
a = b;
22+
b = c;
23+
c = result;
24+
}
25+
return result;
26+
}
27+
// end::answer[]
28+
}

0 commit comments

Comments
 (0)