Skip to content

Commit 3c3f1a3

Browse files
authored
feat: add php solution to lc problem: No.2190 (#992)
1 parent 2e15019 commit 3c3f1a3

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

solution/2100-2199/2190.Most Frequent Number Following Key In an Array/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,32 @@ func mostFrequent(nums []int, key int) int {
145145

146146
```
147147

148+
### **PHP**
149+
150+
```php
151+
class Solution {
152+
/**
153+
* @param Integer[] $nums
154+
* @param Integer $key
155+
* @return Integer
156+
*/
157+
function mostFrequent($nums, $key) {
158+
$max = $maxNum = 0;
159+
for ($i = 0; $i < count($nums) - 1; $i++) {
160+
if ($nums[$i] == $key) {
161+
$hashtable[$nums[$i + 1]] += 1;
162+
$tmp = $hashtable[$nums[$i + 1]];
163+
if ($tmp > $max) {
164+
$max = $tmp;
165+
$maxNum = $nums[$i + 1];
166+
}
167+
}
168+
}
169+
return $maxNum;
170+
}
171+
}
172+
```
173+
148174
### **...**
149175

150176
```

solution/2100-2199/2190.Most Frequent Number Following Key In an Array/README_EN.md

+26
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,32 @@ func mostFrequent(nums []int, key int) int {
137137

138138
```
139139

140+
### **PHP**
141+
142+
```php
143+
class Solution {
144+
/**
145+
* @param Integer[] $nums
146+
* @param Integer $key
147+
* @return Integer
148+
*/
149+
function mostFrequent($nums, $key) {
150+
$max = $maxNum = 0;
151+
for ($i = 0; $i < count($nums) - 1; $i++) {
152+
if ($nums[$i] == $key) {
153+
$hashtable[$nums[$i + 1]] += 1;
154+
$tmp = $hashtable[$nums[$i + 1]];
155+
if ($tmp > $max) {
156+
$max = $tmp;
157+
$maxNum = $nums[$i + 1];
158+
}
159+
}
160+
}
161+
return $maxNum;
162+
}
163+
}
164+
```
165+
140166
### **...**
141167

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

0 commit comments

Comments
 (0)