Skip to content

Commit 185a247

Browse files
authored
feat: add php solutions to lc problem: No.0001 (doocs#896)
No.0001.Two Sum
1 parent 945c8bf commit 185a247

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

solution/0000-0099/0001.Two Sum/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,29 @@ proc twoSum(nums: seq[int], target: int): seq[int] =
230230
tdx = nums.find(bal)
231231
if idx != tdx:
232232
return @[idx, tdx]
233+
```
234+
235+
### **PHP**
236+
237+
```php
238+
class Solution {
233239

240+
/**
241+
* @param Integer[] $nums
242+
* @param Integer $target
243+
* @return Integer[]
244+
*/
245+
function twoSum($nums, $target) {
246+
$len = count($nums);
247+
for ($i = 0; $i < $len; $i++) {
248+
for ($j = 1 + $i; $j < $len; $j++) {
249+
if ($nums[$i] + $nums[$j] == $target) {
250+
return [$i, $j];
251+
}
252+
}
253+
}
254+
}
255+
}
234256
```
235257

236258
### **...**

solution/0000-0099/0001.Two Sum/README_EN.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,29 @@ proc twoSum(nums: seq[int], target: int): seq[int] =
211211
tdx = nums.find(bal)
212212
if idx != tdx:
213213
return @[idx, tdx]
214+
```
215+
216+
### **PHP**
217+
218+
```php
219+
class Solution {
214220

221+
/**
222+
* @param Integer[] $nums
223+
* @param Integer $target
224+
* @return Integer[]
225+
*/
226+
function twoSum($nums, $target) {
227+
$len = count($nums);
228+
for ($i = 0; $i < $len; $i++) {
229+
for ($j = 1 + $i; $j < $len; $j++) {
230+
if ($nums[$i] + $nums[$j] == $target) {
231+
return [$i, $j];
232+
}
233+
}
234+
}
235+
}
236+
}
215237
```
216238

217239
### **...**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
3+
/**
4+
* @param Integer[] $nums
5+
* @param Integer $target
6+
* @return Integer[]
7+
*/
8+
function twoSum($nums, $target) {
9+
$len = count($nums);
10+
for ($i = 0; $i < $len; $i++) {
11+
for ($j = 1 + $i; $j < $len; $j++) {
12+
if ($nums[$i] + $nums[$j] == $target) {
13+
return [$i, $j];
14+
}
15+
}
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)