diff --git a/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README.md b/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README.md index a795e105d7546..2212d8d997cef 100644 --- a/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README.md +++ b/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README.md @@ -112,6 +112,24 @@ var findSpecialInteger = function (arr) { }; ``` +### **PHP** + +```php +class Solution { + /** + * @param Integer[] $arr + * @return Integer + */ + function findSpecialInteger($arr) { + $len = count($arr); + for ($i = 0; $i < $len; $i++) { + if ($arr[$i] == $arr[$i + ($len >> 2)]) return $arr[$i]; + } + return -1; + } +} +``` + ### **...** ``` diff --git a/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md b/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md index eb2c8b9f435e4..58f0df7a8c0b8 100644 --- a/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md +++ b/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README_EN.md @@ -107,6 +107,24 @@ var findSpecialInteger = function (arr) { }; ``` +### **PHP** + +```php +class Solution { + /** + * @param Integer[] $arr + * @return Integer + */ + function findSpecialInteger($arr) { + $len = count($arr); + for ($i = 0; $i < $len; $i++) { + if ($arr[$i] == $arr[$i + ($len >> 2)]) return $arr[$i]; + } + return -1; + } +} +``` + ### **...** ``` diff --git a/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.php b/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.php new file mode 100644 index 0000000000000..0bb791071d335 --- /dev/null +++ b/solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/Solution.php @@ -0,0 +1,13 @@ +class Solution { + /** + * @param Integer[] $arr + * @return Integer + */ + function findSpecialInteger($arr) { + $len = count($arr); + for ($i = 0; $i < $len; $i++) { + if ($arr[$i] == $arr[$i + ($len >> 2)]) return $arr[$i]; + } + return -1; + } +} \ No newline at end of file