From fe474762a6ccf142a7094de2be0e5312b97504a1 Mon Sep 17 00:00:00 2001 From: Qiu-IT Date: Fri, 5 May 2023 11:05:50 +0200 Subject: [PATCH] feat: add php solution to lc problem: No.1213 --- .../README.md | 22 +++++++++++++++++++ .../README_EN.md | 22 +++++++++++++++++++ .../Solution.php | 17 ++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 solution/1200-1299/1213.Intersection of Three Sorted Arrays/Solution.php diff --git a/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README.md b/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README.md index 8958b144a4748..b6b24554e5851 100644 --- a/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README.md +++ b/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README.md @@ -193,6 +193,28 @@ func arraysIntersection(arr1 []int, arr2 []int, arr3 []int) (ans []int) { } ``` +### **PHP** + +```php +class Solution { + /** + * @param Integer[] $arr1 + * @param Integer[] $arr2 + * @param Integer[] $arr3 + * @return Integer[] + */ + function arraysIntersection($arr1, $arr2, $arr3) { + $rs = []; + $arr = array_merge($arr1, $arr2, $arr3); + for ($i = 0; $i < count($arr); $i++) { + $hashtable[$arr[$i]] += 1; + if ($hashtable[$arr[$i]] === 3) array_push($rs, $arr[$i]); + } + return $rs; + } +} +``` + ### **...** ``` diff --git a/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README_EN.md b/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README_EN.md index 62c7789609ba1..d193a5bd61186 100644 --- a/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README_EN.md +++ b/solution/1200-1299/1213.Intersection of Three Sorted Arrays/README_EN.md @@ -173,6 +173,28 @@ func arraysIntersection(arr1 []int, arr2 []int, arr3 []int) (ans []int) { } ``` +### **PHP** + +```php +class Solution { + /** + * @param Integer[] $arr1 + * @param Integer[] $arr2 + * @param Integer[] $arr3 + * @return Integer[] + */ + function arraysIntersection($arr1, $arr2, $arr3) { + $rs = []; + $arr = array_merge($arr1, $arr2, $arr3); + for ($i = 0; $i < count($arr); $i++) { + $hashtable[$arr[$i]] += 1; + if ($hashtable[$arr[$i]] === 3) array_push($rs, $arr[$i]); + } + return $rs; + } +} +``` + ### **...** ``` diff --git a/solution/1200-1299/1213.Intersection of Three Sorted Arrays/Solution.php b/solution/1200-1299/1213.Intersection of Three Sorted Arrays/Solution.php new file mode 100644 index 0000000000000..424afcfd4ba31 --- /dev/null +++ b/solution/1200-1299/1213.Intersection of Three Sorted Arrays/Solution.php @@ -0,0 +1,17 @@ +class Solution { + /** + * @param Integer[] $arr1 + * @param Integer[] $arr2 + * @param Integer[] $arr3 + * @return Integer[] + */ + function arraysIntersection($arr1, $arr2, $arr3) { + $rs = []; + $arr = array_merge($arr1, $arr2, $arr3); + for ($i = 0; $i < count($arr); $i++) { + $hashtable[$arr[$i]] += 1; + if ($hashtable[$arr[$i]] === 3) array_push($rs, $arr[$i]); + } + return $rs; + } +} \ No newline at end of file