Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add php solution to lc problem: No.0229 #964

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions solution/0200-0299/0229.Majority Element II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,27 @@ public class Solution {
}
```

### **PHP**

```php
class Solution {
/**
* @param Integer[] $nums
* @return Integer[]
*/
function majorityElement($nums) {
$rs = [];
$n = count($nums);
for ($i = 0; $i < $n; $i++) {
$hashmap[$nums[$i]] += 1;
if ($hashmap[$nums[$i]] > $n / 3)
array_push($rs, $nums[$i]);
}
return array_unique($rs);
}
}
```

### **...**

```
Expand Down
21 changes: 21 additions & 0 deletions solution/0200-0299/0229.Majority Element II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,27 @@ public class Solution {
}
```

### **PHP**

```php
class Solution {
/**
* @param Integer[] $nums
* @return Integer[]
*/
function majorityElement($nums) {
$rs = [];
$n = count($nums);
for ($i = 0; $i < $n; $i++) {
$hashmap[$nums[$i]] += 1;
if ($hashmap[$nums[$i]] > $n / 3)
array_push($rs, $nums[$i]);
}
return array_unique($rs);
}
}
```

### **...**

```
Expand Down
16 changes: 16 additions & 0 deletions solution/0200-0299/0229.Majority Element II/Solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
/**
* @param Integer[] $nums
* @return Integer[]
*/
function majorityElement($nums) {
$rs = [];
$n = count($nums);
for ($i = 0; $i < $n; $i++) {
$hashmap[$nums[$i]] += 1;
if ($hashmap[$nums[$i]] > $n / 3)
array_push($rs, $nums[$i]);
}
return array_unique($rs);
}
}