Skip to content

Commit c820e47

Browse files
authored
feat: add php solution to lc problem: No.1426 (doocs#1016)
1 parent 21d8662 commit c820e47

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/1400-1499/1426.Counting Elements/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,24 @@ var countElements = function (arr) {
213213
};
214214
```
215215

216+
### **PHP**
217+
218+
```php
219+
class Solution {
220+
/**
221+
* @param Integer[] $arr
222+
* @return Integer
223+
*/
224+
function countElements($arr) {
225+
$cnt = 0;
226+
for ($i = 0; $i < count($arr); $i++) {
227+
if (in_array($arr[$i] + 1, $arr)) $cnt++;
228+
}
229+
return $cnt++;
230+
}
231+
}
232+
```
233+
216234
### **...**
217235

218236
```

solution/1400-1499/1426.Counting Elements/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,24 @@ var countElements = function (arr) {
190190
};
191191
```
192192

193+
### **PHP**
194+
195+
```php
196+
class Solution {
197+
/**
198+
* @param Integer[] $arr
199+
* @return Integer
200+
*/
201+
function countElements($arr) {
202+
$cnt = 0;
203+
for ($i = 0; $i < count($arr); $i++) {
204+
if (in_array($arr[$i] + 1, $arr)) $cnt++;
205+
}
206+
return $cnt++;
207+
}
208+
}
209+
```
210+
193211
### **...**
194212

195213
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
/**
3+
* @param Integer[] $arr
4+
* @return Integer
5+
*/
6+
function countElements($arr) {
7+
$cnt = 0;
8+
for ($i = 0; $i < count($arr); $i++) {
9+
if (in_array($arr[$i] + 1, $arr)) $cnt++;
10+
}
11+
return $cnt++;
12+
}
13+
}

0 commit comments

Comments
 (0)