<?php
class Solution {
/**
* @param Integer[] $nums
* @param Integer $target
* @return Integer[]
*/
function twoSum($nums, $target) {
$diffMap = [];
for ($i = 0; $i < count($nums); $i++) {
$diff = $target - $nums[$i];
if (array_key_exists($diff, $diffMap)) {
return [$diffMap[$diff], $i];
}
$diffMap[$nums[$i]] = $i;
}
return [];
}
}
$sol = new Solution();
print_r($sol->twoSum([1, 2, 3, 4, 5], 9));
To embed this project on your website, copy the following code and paste it into your website's HTML: