Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public function twoSum(array $nums, int $target) {
- $c = count($nums);
- #$n = array_combine( array_values($nums), array_keys($nums) );
- $n = [];
- for($i=0;$i<$c;$i++){
- $x = $target - $nums[$i];
- if(array_key_exists($x, $n)){
- return [ $n[$x], $i ];
- }
- $n[$nums[$i]] = $i;
- }
- return [];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment