File tree 3 files changed +58
-0
lines changed
solution/0200-0299/0229.Majority Element II
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -230,6 +230,27 @@ public class Solution {
230
230
}
231
231
```
232
232
233
+ ### ** PHP**
234
+
235
+ ``` php
236
+ class Solution {
237
+ /**
238
+ * @param Integer[] $nums
239
+ * @return Integer[]
240
+ */
241
+ function majorityElement($nums) {
242
+ $rs = [];
243
+ $n = count($nums);
244
+ for ($i = 0; $i < $n; $i++) {
245
+ $hashmap[$nums[$i]] += 1;
246
+ if ($hashmap[$nums[$i]] > $n / 3)
247
+ array_push($rs, $nums[$i]);
248
+ }
249
+ return array_unique($rs);
250
+ }
251
+ }
252
+ ```
253
+
233
254
### ** ...**
234
255
235
256
```
Original file line number Diff line number Diff line change @@ -219,6 +219,27 @@ public class Solution {
219
219
}
220
220
```
221
221
222
+ ### ** PHP**
223
+
224
+ ``` php
225
+ class Solution {
226
+ /**
227
+ * @param Integer[] $nums
228
+ * @return Integer[]
229
+ */
230
+ function majorityElement($nums) {
231
+ $rs = [];
232
+ $n = count($nums);
233
+ for ($i = 0; $i < $n; $i++) {
234
+ $hashmap[$nums[$i]] += 1;
235
+ if ($hashmap[$nums[$i]] > $n / 3)
236
+ array_push($rs, $nums[$i]);
237
+ }
238
+ return array_unique($rs);
239
+ }
240
+ }
241
+ ```
242
+
222
243
### ** ...**
223
244
224
245
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param Integer[] $nums
4
+ * @return Integer[]
5
+ */
6
+ function majorityElement ($nums ) {
7
+ $rs = [];
8
+ $n = count ($nums );
9
+ for ($i = 0 ; $i < $n ; $i ++ ) {
10
+ $hashmap [$nums [$i ]] += 1 ;
11
+ if ($hashmap [$nums [$i ]] > $n / 3 )
12
+ array_push ($rs , $nums [$i ]);
13
+ }
14
+ return array_unique ($rs );
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments