Skip to content

Instantly share code, notes, and snippets.

@slav123
Created April 24, 2020 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slav123/f023bd687840496a29381b49a342ebbf to your computer and use it in GitHub Desktop.
Save slav123/f023bd687840496a29381b49a342ebbf to your computer and use it in GitHub Desktop.
twoSum.php
<?php
function twoSum($nums, $target) {
for($a = 0, $max = count($nums);$a < $max-1; $a++) {
$looking = $target - $nums[$a];
$where = array_slice($nums, $a+1);
$match = array_search($looking, $where);
if ($match !== false) {
return [$a, $match+$a+1];
}
}
return[0,0];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment