From ff579dda064ef3c4a3fb33c7aa1623275bfd506b Mon Sep 17 00:00:00 2001 From: Qiu-IT Date: Wed, 31 May 2023 10:39:11 +0200 Subject: [PATCH] feat: add php solution to lc problem: No.1426 --- .../1400-1499/1426.Counting Elements/README.md | 18 ++++++++++++++++++ .../1426.Counting Elements/README_EN.md | 18 ++++++++++++++++++ .../1426.Counting Elements/Solution.php | 13 +++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 solution/1400-1499/1426.Counting Elements/Solution.php diff --git a/solution/1400-1499/1426.Counting Elements/README.md b/solution/1400-1499/1426.Counting Elements/README.md index 90f2d1b697d42..ec6a0ece881f6 100644 --- a/solution/1400-1499/1426.Counting Elements/README.md +++ b/solution/1400-1499/1426.Counting Elements/README.md @@ -213,6 +213,24 @@ var countElements = function (arr) { }; ``` +### **PHP** + +```php +class Solution { + /** + * @param Integer[] $arr + * @return Integer + */ + function countElements($arr) { + $cnt = 0; + for ($i = 0; $i < count($arr); $i++) { + if (in_array($arr[$i] + 1, $arr)) $cnt++; + } + return $cnt++; + } +} +``` + ### **...** ``` diff --git a/solution/1400-1499/1426.Counting Elements/README_EN.md b/solution/1400-1499/1426.Counting Elements/README_EN.md index 18f80783e2921..f507a2b3659b6 100644 --- a/solution/1400-1499/1426.Counting Elements/README_EN.md +++ b/solution/1400-1499/1426.Counting Elements/README_EN.md @@ -190,6 +190,24 @@ var countElements = function (arr) { }; ``` +### **PHP** + +```php +class Solution { + /** + * @param Integer[] $arr + * @return Integer + */ + function countElements($arr) { + $cnt = 0; + for ($i = 0; $i < count($arr); $i++) { + if (in_array($arr[$i] + 1, $arr)) $cnt++; + } + return $cnt++; + } +} +``` + ### **...** ``` diff --git a/solution/1400-1499/1426.Counting Elements/Solution.php b/solution/1400-1499/1426.Counting Elements/Solution.php new file mode 100644 index 0000000000000..047793b09fdda --- /dev/null +++ b/solution/1400-1499/1426.Counting Elements/Solution.php @@ -0,0 +1,13 @@ +class Solution { + /** + * @param Integer[] $arr + * @return Integer + */ + function countElements($arr) { + $cnt = 0; + for ($i = 0; $i < count($arr); $i++) { + if (in_array($arr[$i] + 1, $arr)) $cnt++; + } + return $cnt++; + } +} \ No newline at end of file