Skip to content

Commit 0593fbd

Browse files
Qiu-ITQiu-IT
authored andcommitted
feat: add php solutions to lc problem: No.0001
1 parent 8cfd935 commit 0593fbd

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,15 @@ class Solution {
254254
* @return Integer[]
255255
*/
256256
function twoSum($nums, $target) {
257-
$len = count($nums);
258-
for ($i=0; $i<$len; $i++) {
259-
for ($j=1+$i; $j<$len; $j++) {
260-
if($nums[$i]+$nums[$j]==$target)
261-
{
262-
return [$i,$j];
257+
$len = count($nums);
258+
for ($i = 0; $i < $len; $i++) {
259+
for ($j = 1 + $i; $j < $len; $j++) {
260+
if ($nums[$i] + $nums[$j] == $target) {
261+
return [$i, $j];
262+
}
263263
}
264264
}
265265
}
266-
}
267266
}
268267
```
269268

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,15 @@ class Solution {
235235
* @return Integer[]
236236
*/
237237
function twoSum($nums, $target) {
238-
$len = count($nums);
239-
for ($i=0; $i<$len; $i++) {
240-
for ($j=1+$i; $j<$len; $j++) {
241-
if($nums[$i]+$nums[$j]==$target)
242-
{
243-
return [$i,$j];
238+
$len = count($nums);
239+
for ($i = 0; $i < $len; $i++) {
240+
for ($j = 1 + $i; $j < $len; $j++) {
241+
if ($nums[$i] + $nums[$j] == $target) {
242+
return [$i, $j];
243+
}
244244
}
245245
}
246246
}
247-
}
248247
}
249248
```
250249

solution/0000-0099/0001.Two Sum/Solution.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ class Solution {
66
* @return Integer[]
77
*/
88
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-
{
14-
return [$i,$j];
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+
}
1515
}
1616
}
1717
}
18-
}
1918
}

0 commit comments

Comments
 (0)