diff --git a/solution/0000-0099/0001.Two Sum/README.md b/solution/0000-0099/0001.Two Sum/README.md index 3f088baab86f6..5c58d58948960 100644 --- a/solution/0000-0099/0001.Two Sum/README.md +++ b/solution/0000-0099/0001.Two Sum/README.md @@ -230,7 +230,29 @@ proc twoSum(nums: seq[int], target: int): seq[int] = tdx = nums.find(bal) if idx != tdx: return @[idx, tdx] +``` + +### **PHP** + +```php +class Solution { + /** + * @param Integer[] $nums + * @param Integer $target + * @return Integer[] + */ + function twoSum($nums, $target) { + $len = count($nums); + for ($i = 0; $i < $len; $i++) { + for ($j = 1 + $i; $j < $len; $j++) { + if ($nums[$i] + $nums[$j] == $target) { + return [$i, $j]; + } + } + } + } +} ``` ### **...** diff --git a/solution/0000-0099/0001.Two Sum/README_EN.md b/solution/0000-0099/0001.Two Sum/README_EN.md index 85a10c9a7f29f..636e8ecf7eba2 100644 --- a/solution/0000-0099/0001.Two Sum/README_EN.md +++ b/solution/0000-0099/0001.Two Sum/README_EN.md @@ -211,7 +211,29 @@ proc twoSum(nums: seq[int], target: int): seq[int] = tdx = nums.find(bal) if idx != tdx: return @[idx, tdx] +``` + +### **PHP** + +```php +class Solution { + /** + * @param Integer[] $nums + * @param Integer $target + * @return Integer[] + */ + function twoSum($nums, $target) { + $len = count($nums); + for ($i = 0; $i < $len; $i++) { + for ($j = 1 + $i; $j < $len; $j++) { + if ($nums[$i] + $nums[$j] == $target) { + return [$i, $j]; + } + } + } + } +} ``` ### **...** diff --git a/solution/0000-0099/0001.Two Sum/Solution.php b/solution/0000-0099/0001.Two Sum/Solution.php new file mode 100644 index 0000000000000..f6105adcaf2d6 --- /dev/null +++ b/solution/0000-0099/0001.Two Sum/Solution.php @@ -0,0 +1,18 @@ +class Solution { + + /** + * @param Integer[] $nums + * @param Integer $target + * @return Integer[] + */ + function twoSum($nums, $target) { + $len = count($nums); + for ($i = 0; $i < $len; $i++) { + for ($j = 1 + $i; $j < $len; $j++) { + if ($nums[$i] + $nums[$j] == $target) { + return [$i, $j]; + } + } + } + } +} \ No newline at end of file