10000 clean up · dotmarn/algorithm-solution@4e054b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e054b2

Browse files
committed
clean up
1 parent 1b1580d commit 4e054b2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Two Sum/twosum.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ class Solution {
88
* @return Integer[]
99
*/
1010
function twoSum($nums, $target) {
11-
$count = 1;
12-
$result = [];
13-
foreach($nums as $key => $value) {
14-
$sum = $value + $nums[$count + $key];
15-
if($sum == $target) {
16-
$result = [$key, $count + $key];
11+
$length = count($nums) - 1;
12+
for($i = 0; $i <= $length; $i++) {
13+
for($j = $i + 1; $j <= $length; $j++) {
14+
$sum = $nums[$i] + $nums[$j];
15+
if ($sum === $target) {
16+
$result = [$i, $j];
17+
}
1718
}
19+
1820
}
1921

2022
return $result;

0 commit comments

Comments
 (0)
0