File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed
solution/0300-0399/0350.Intersection of Two Arrays II Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -199,6 +199,31 @@ impl Solution {
199
199
}
200
200
```
201
201
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
+
202
227
### ** ...**
203
228
204
229
```
Original file line number Diff line number Diff line change @@ -188,6 +188,31 @@ impl Solution {
188
188
}
189
189
```
190
190
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
+
191
216
### ** ...**
192
217
193
218
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments