File tree 3 files changed +67
-0
lines changed
solution/2400-2499/2404.Most Frequent Even Element
3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,30 @@ impl Solution {
187
187
}
188
188
```
189
189
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
+
190
214
### ** ...**
191
215
192
216
```
Original file line number Diff line number Diff line change @@ -174,6 +174,30 @@ impl Solution {
174
174
}
175
175
```
176
176
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
+
177
201
### ** ...**
178
202
179
203
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments