Skip to content

Commit

Permalink
添加 0454.四数相加II PHP版本
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanzzz committed Sep 3, 2021
1 parent 7f7d1ee commit 80eb43f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion problems/0454.四数相加II.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,37 @@ var fourSumCount = function(nums1, nums2, nums3, nums4) {
};
```


PHP:
```php
class Solution {
/**
* @param Integer[] $nums1
* @param Integer[] $nums2
* @param Integer[] $nums3
* @param Integer[] $nums4
* @return Integer
*/
function fourSumCount($nums1, $nums2, $nums3, $nums4) {
$map = [];
foreach ($nums1 as $n1) {
foreach ($nums2 as $n2) {
$temp = $n1 + $n2;
$map[$temp] = isset($map[$temp]) ? $map[$temp]+1 : 1;
}
}
$count = 0;
foreach ($nums3 as $n3) {
foreach ($nums4 as $n4) {
$temp = 0 - $n3 - $n4;
if (isset($map[$temp])) {
$count += $map[$temp];
}
}
}
return $count;
}
}
```


-----------------------
Expand Down

0 comments on commit 80eb43f

Please sign in to comment.