Created
April 24, 2020 10:29
-
-
Save slav123/f023bd687840496a29381b49a342ebbf to your computer and use it in GitHub Desktop.
twoSum.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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