Skip to content

Commit 1b8e686

Browse files
authored
feat: add php solution to lc problem: No.0349 (doocs#960)
1 parent ca289c7 commit 1b8e686

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,30 @@ func intersection(nums1 []int, nums2 []int) []int {
148148
}
149149
```
150150

151+
### **PHP**
152+
153+
```php
154+
class Solution {
155+
/**
156+
* @param Integer[] $nums1
157+
* @param Integer[] $nums2
158+
* @return Integer[]
159+
*/
160+
function intersection($nums1, $nums2) {
161+
$rs = [];
162+
$set1 = array_values(array_unique($nums1));
163+
$set2 = array_values(array_unique($nums2));
164+
for ($i = 0; $i < count($set1); $i++) {
165+
$hashmap[$set1[$i]] = 1;
166+
}
167+
for ($j = 0; $j < count($set2); $j++) {
168+
if ($hashmap[$set2[$j]]) array_push($rs, $set2[$j]);
169+
}
170+
return $rs;
171+
}
172+
}
173+
```
174+
151175
### **...**
152176

153177
```

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,30 @@ func intersection(nums1 []int, nums2 []int) []int {
136136
}
137137
```
138138

139+
### **PHP**
140+
141+
```php
142+
class Solution {
143+
/**
144+
* @param Integer[] $nums1
145+
* @param Integer[] $nums2
146+
* @return Integer[]
147+
*/
148+
function intersection($nums1, $nums2) {
149+
$rs = [];
150+
$set1 = array_values(array_unique($nums1));
151+
$set2 = array_values(array_unique($nums2));
152+
for ($i = 0; $i < count($set1); $i++) {
153+
$hashmap[$set1[$i]] = 1;
154+
}
155+
for ($j = 0; $j < count($set2); $j++) {
156+
if ($hashmap[$set2[$j]]) array_push($rs, $set2[$j]);
157+
}
158+
return $rs;
159+
}
160+
}
161+
```
162+
139163
### **...**
140164

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

0 commit comments

Comments
 (0)