Skip to content

Commit f89643f

Browse files
authored
feat: add php solution to lc problem: No.0229 (doocs#964)
1 parent 06516ce commit f89643f

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

solution/0200-0299/0229.Majority Element II/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,27 @@ public class Solution {
230230
}
231231
```
232232

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+
233254
### **...**
234255

235256
```

solution/0200-0299/0229.Majority Element II/README_EN.md

+21
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,27 @@ public class Solution {
219219
}
220220
```
221221

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+
222243
### **...**
223244

224245
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

0 commit comments

Comments
 (0)