File tree 3 files changed +64
-0
lines changed
solution/1100-1199/1137.N-th Tribonacci Number
3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,29 @@ var tribonacci = function (n) {
137
137
};
138
138
```
139
139
140
+ ### ** PHP**
141
+
142
+ ``` php
143
+ class Solution {
144
+ /**
145
+ * @param Integer $n
146
+ * @return Integer
147
+ */
148
+ function tribonacci($n) {
149
+ if ($n == 0) {
150
+ return 0;
151
+ } else if ($n == 1 || $n == 2) {
152
+ return 1;
153
+ }
154
+ $dp = [0, 1, 1];
155
+ for ($i = 3; $i <= $n; $i++) {
156
+ $dp[$i] = $dp[$i - 1] + $dp[$i - 2] + $dp[$i - 3];
157
+ }
158
+ return $dp[$n];
159
+ }
160
+ }
161
+ ```
162
+
140
163
### ** ...**
141
164
142
165
```
Original file line number Diff line number Diff line change @@ -130,6 +130,29 @@ var tribonacci = function (n) {
130
130
};
131
131
```
132
132
133
+ ### ** PHP**
134
+
135
+ ``` php
136
+ class Solution {
137
+ /**
138
+ * @param Integer $n
139
+ * @return Integer
140
+ */
141
+ function tribonacci($n) {
142
+ if ($n == 0) {
143
+ return 0;
144
+ } else if ($n == 1 || $n == 2) {
145
+ return 1;
146
+ }
147
+ $dp = [0, 1, 1];
148
+ for ($i = 3; $i <= $n; $i++) {
149
+ $dp[$i] = $dp[$i - 1] + $dp[$i - 2] + $dp[$i - 3];
150
+ }
151
+ return $dp[$n];
152
+ }
153
+ }
154
+ ```
155
+
133
156
### ** ...**
134
157
135
158
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param Integer $n
4
+ * @return Integer
5
+ */
6
+ function tribonacci ($n ) {
7
+ if ($n == 0 ) {
8
+ return 0 ;
9
+ } else if ($n == 1 || $n == 2 ) {
10
+ return 1 ;
11
+ }
12
+ $dp = [0 , 1 , 1 ];
13
+ for ($i = 3 ; $i <= $n ; $i ++ ) {
14
+ $dp [$i ] = $dp [$i - 1 ] + $dp [$i - 2 ] + $dp [$i - 3 ];
15
+ }
16
+ return $dp [$n ];
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments