Skip to content

Commit 1272d44

Browse files
authored
feat add php solution to lc problem: No.0350 (doocs#963)
1 parent bb1095e commit 1272d44

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

solution/0300-0399/0350.Intersection of Two Arrays II/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,31 @@ impl Solution {
199199
}
200200
```
201201

202+
### **PHP**
203+
204+
```php
205+
class Solution {
206+
/**
207+
* @param Integer[] $nums1
208+
* @param Integer[] $nums2
209+
* @return Integer[]
210+
*/
211+
function intersect($nums1, $nums2) {
212+
$rs = [];
213+
for ($i = 0; $i < count($nums1); $i++) {
214+
$hashtable[$nums1[$i]] += 1;
215+
}
216+
for ($j = 0; $j < count($nums2); $j++) {
217+
if (isset($hashtable[$nums2[$j]]) && $hashtable[$nums2[$j]] > 0) {
218+
array_push($rs, $nums2[$j]);
219+
$hashtable[$nums2[$j]] -= 1;
220+
}
221+
}
222+
return $rs;
223+
}
224+
}
225+
```
226+
202227
### **...**
203228

204229
```

solution/0300-0399/0350.Intersection of Two Arrays II/README_EN.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,31 @@ impl Solution {
188188
}
189189
```
190190

191+
### **PHP**
192+
193+
```php
194+
class Solution {
195+
/**
196+
* @param Integer[] $nums1
197+
* @param Integer[] $nums2
198+
* @return Integer[]
199+
*/
200+
function intersect($nums1, $nums2) {
201+
$rs = [];
202+
for ($i = 0; $i < count($nums1); $i++) {
203+
$hashtable[$nums1[$i]] += 1;
204+
}
205+
for ($j = 0; $j < count($nums2); $j++) {
206+
if (isset($hashtable[$nums2[$j]]) && $hashtable[$nums2[$j]] > 0) {
207+
array_push($rs, $nums2[$j]);
208+
$hashtable[$nums2[$j]] -= 1;
209+
}
210+
}
211+
return $rs;
212+
}
213+
}
214+
```
215+
191216
### **...**
192217

193218
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
/**
3+
* @param Integer[] $nums1
4+
* @param Integer[] $nums2
5+
* @return Integer[]
6+
*/
7+
function intersect($nums1, $nums2) {
8+
$rs = [];
9+
for ($i = 0; $i < count($nums1); $i++) {
10+
$hashtable[$nums1[$i]] += 1;
11+
}
12+
for ($j = 0; $j < count($nums2); $j++) {
13+
if (isset($hashtable[$nums2[$j]]) && $hashtable[$nums2[$j]] > 0) {
14+
array_push($rs, $nums2[$j]);
15+
$hashtable[$nums2[$j]] -= 1;
16+
}
17+
}
18+
return $rs;
19+
}
20+
}

0 commit comments

Comments
 (0)