PHP-leetcode-53

littlehero發表於2019-09-08
function maxSubArray($nums)
{
    $len = count($nums);
    $max = $nums[0];
    for ($i = 1; $i < $len; $i++) {
        $nums[$i] = max(0, $nums[$i - 1]) + $nums[$i];
        if ($nums[$i] > $max) $max = $nums[$i];
    }
    return $max;
}