- Output for 7.1.0 - 7.1.23, 7.2.0 - 7.2.11
- bool(true) bool(false)
- Output for 5.6.38
- Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/VJf7L on line 10
Process exited with code 255.
<?php
final class ArrayUtils
{
private static $visited = [];
private static $sum = 0;
private static $data = [];
public static function containsSum(array $data, int $sum): bool
{
self::$data = $data;
self::$sum = $sum;
self::$visited = [];
return self::found();
}
private static function found(): bool
{
if (! self::$data) {
return false;
}
$value = array_pop(self::$data);
if (isset(self::$visited[self::$sum - $value])) {
return true;
}
self::$visited[$value] = true;
return self::found();
}
}
$data = range(0, 49999);
shuffle($data);
var_dump(ArrayUtils::containsSum($data, 1220));
var_dump(ArrayUtils::containsSum($data, -7));