Skip to content

Commit 1c55de3

Browse files
solve 1-two-sum problem
1 parent f2b857a commit 1c55de3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

1-two-sum.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const twoSum = (nums, target) => {
2+
let result = [];
3+
for (let i = 0; i < nums.length; i++) {
4+
for (let j = i + 1; j < nums.length; j++) {
5+
if (nums[i] + nums[j] === target) {
6+
result.push(i, j);
7+
}
8+
}
9+
}
10+
return result;
11+
};
12+
13+
twoSum([2, 7, 11, 15], 9);

0 commit comments

Comments
 (0)