File tree 3 files changed +73
-0
lines changed
solution/2100-2199/2190.Most Frequent Number Following Key In an Array
3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,32 @@ func mostFrequent(nums []int, key int) int {
145
145
146
146
```
147
147
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
+
148
174
### ** ...**
149
175
150
176
```
Original file line number Diff line number Diff line change @@ -137,6 +137,32 @@ func mostFrequent(nums []int, key int) int {
137
137
138
138
```
139
139
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
+
140
166
### ** ...**
141
167
142
168
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments