Skip to content

Commit

Permalink
Fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev committed Dec 22, 2023
1 parent 6e4545c commit a5d0796
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/Solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

class Solution {

/**
* @param Integer[] $nums
* @param Integer $target
* @return Integer[]
*/
function twoSum($nums, $target) {
$map = [];
for ($i = 0; $i < count($nums); $i++) {
$map[$nums[$i]] = $i;
}
for ($i = 0; $i < count($nums); $i++) {
$complement = $target - $nums[$i];
if (array_key_exists($complement, $map) && $map[$complement] != $i) {
return [$i, $map[$complement] ];
}
}
throw new IllegalArgumentException("No two sum solution");
}
}

0 comments on commit a5d0796

Please sign in to comment.