8000 added solution to two sum · dotmarn/algorithm-solution@b966aa2 · GitHub
[go: up one dir, main page]

Skip to content

Commit b966aa2

Browse files
committed
added solution to two sum
0 parents  commit b966aa2

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

.vscode/settings.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"workbench.colorCustomizations": {
3+
"activityBar.activeBackground": "#471216",
4+
"activityBar.activeBorder": "#20661a",
5+
"activityBar.background": "#471216",
6+
"activityBar.foreground": "#e7e7e7",
7+
"activityBar.inactiveForeground": "#e7e7e799",
8+
"activityBarBadge.background": "#20661a",
9+
"activityBarBadge.foreground": "#e7e7e7",
10+
"sash.hoverBorder": "#471216",
11+
"statusBar.background": "#471216",
12+
"statusBar.foreground": "#e7e7e7",
13+
"statusBarItem.hoverBackground": "#701c23",
14+
"statusBarItem.remoteBackground": "#471216",
15+
"statusBarItem.remoteForeground": "#e7e7e7",
16+
"titleBar.activeBackground": "#471216",
17+
"titleBar.activeForeground": "#e7e7e7",
18+
"titleBar.inactiveBackground": "#47121699",
19+
"titleBar.inactiveForeground": "#e7e7e799"
20+
},
21+
"peacock.color": "#6f1d23"
22+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# algorithm-solution

Two Sum/twosum.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
class Solution {
4+
5+
/**
6+
* @param Integer[] $nums
7+
* @param Integer $target
8+
* @return Integer[]
9+
*/
10+
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];
17+
}
18+
}
19+
20+
return $result;
21+
}
22+
}

0 commit comments

Comments
 (0)
0