Skip to content

Commit 32cbb4f

Browse files
authored
feat: add php solution to lcci problem: No.16.17 (doocs#997)
1 parent ebacdf3 commit 32cbb4f

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

lcci/16.17.Contiguous Sequence/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,29 @@ var maxSubArray = function (nums) {
193193
};
194194
```
195195

196-
### **...**
196+
### **PHP**
197197

198+
```php
199+
class Solution {
200+
/**
201+
* @param Integer[] $nums
202+
* @return Integer
203+
*/
204+
function maxSubArray($nums) {
205+
$pre = 0;
206+
$max = $nums[0];
207+
for ($i = 0; $i < count($nums); $i++) {
208+
$pre = max($pre + $nums[$i], $nums[$i]);
209+
$max = max($pre, $max);
210+
}
211+
return $max;
212+
}
213+
}
198214
```
199215

216+
### **...**
217+
218+
```
200219
201220
```
202221

lcci/16.17.Contiguous Sequence/README_EN.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,29 @@ var maxSubArray = function (nums) {
201201
};
202202
```
203203

204-
### **...**
204+
### **PHP**
205205

206+
```php
207+
class Solution {
208+
/**
209+
* @param Integer[] $nums
210+
* @return Integer
211+
*/
212+
function maxSubArray($nums) {
213+
$pre = 0;
214+
$max = $nums[0];
215+
for ($i = 0; $i < count($nums); $i++) {
216+
$pre = max($pre + $nums[$i], $nums[$i]);
217+
$max = max($pre, $max);
218+
}
219+
return $max;
220+
}
221+
}
206222
```
207223

224+
### **...**
225+
226+
```
208227
209228
```
210229

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
/**
3+
* @param Integer[] $nums
4+
* @return Integer
5+
*/
6+
function maxSubArray($nums) {
7+
$pre = 0;
8+
$max = $nums[0];
9+
for ($i = 0; $i < count($nums); $i++) {
10+
$pre = max($pre + $nums[$i], $nums[$i]);
11+
$max = max($pre, $max);
12+
}
13+
return $max;
14+
}
15+
}

0 commit comments

Comments
 (0)