Skip to content

Commit adbe83c

Browse files
authored
feat: add php solution to lc problem: No.1137 (doocs#935)
1 parent b29a407 commit adbe83c

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

solution/1100-1199/1137.N-th Tribonacci Number/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,29 @@ var tribonacci = function (n) {
137137
};
138138
```
139139

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+
140163
### **...**
141164

142165
```

solution/1100-1199/1137.N-th Tribonacci Number/README_EN.md

+23
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,29 @@ var tribonacci = function (n) {
130130
};
131131
```
132132

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+
133156
### **...**
134157

135158
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

0 commit comments

Comments
 (0)