Skip to content

Commit 013bcd2

Browse files
authored
feat: add php solution to lc problem: No.2404 (doocs#1003)
1 parent 0f27730 commit 013bcd2

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

solution/2400-2499/2404.Most Frequent Even Element/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,30 @@ impl Solution {
187187
}
188188
```
189189

190+
### **PHP**
191+
192+
```php
193+
class Solution {
194+
/**
195+
* @param Integer[] $nums
196+
* @return Integer
197+
*/
198+
function mostFrequentEven($nums) {
199+
$max = $rs = -1;
200+
for ($i = 0; $i < count($nums); $i++) {
201+
if ($nums[$i] % 2 == 0) {
202+
$hashtable[$nums[$i]] += 1;
203+
if ($hashtable[$nums[$i]] > $max || ($hashtable[$nums[$i]] == $max && $rs > $nums[$i])) {
204+
$max = $hashtable[$nums[$i]];
205+
$rs = $nums[$i];
206+
}
207+
}
208+
}
209+
return $rs;
210+
}
211+
}
212+
```
213+
190214
### **...**
191215

192216
```

solution/2400-2499/2404.Most Frequent Even Element/README_EN.md

+24
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,30 @@ impl Solution {
174174
}
175175
```
176176

177+
### **PHP**
178+
179+
```php
180+
class Solution {
181+
/**
182+
* @param Integer[] $nums
183+
* @return Integer
184+
*/
185+
function mostFrequentEven($nums) {
186+
$max = $rs = -1;
187+
for ($i = 0; $i < count($nums); $i++) {
188+
if ($nums[$i] % 2 == 0) {
189+
$hashtable[$nums[$i]] += 1;
190+
if ($hashtable[$nums[$i]] > $max || ($hashtable[$nums[$i]] == $max && $rs > $nums[$i])) {
191+
$max = $hashtable[$nums[$i]];
192+
$rs = $nums[$i];
193+
}
194+
}
195+
}
196+
return $rs;
197+
}
198+
}
199+
```
200+
177201
### **...**
178202

179203
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
/**
3+
* @param Integer[] $nums
4+
* @return Integer
5+
*/
6+
function mostFrequentEven($nums) {
7+
$max = $rs = -1;
8+
for ($i = 0; $i < count($nums); $i++) {
9+
if ($nums[$i] % 2 == 0) {
10+
$hashtable[$nums[$i]] += 1;
11+
if ($hashtable[$nums[$i]] > $max || ($hashtable[$nums[$i]] == $max && $rs > $nums[$i])) {
12+
$max = $hashtable[$nums[$i]];
13+
$rs = $nums[$i];
14+
}
15+
}
16+
}
17+
return $rs;
18+
}
19+
}

0 commit comments

Comments
 (0)