Skip to content

Commit f54ba5c

Browse files
simple coding challenge
1 parent d1b2623 commit f54ba5c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

twosum.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.
3+
*/
4+
5+
var twoSum = function (nums, target) {
6+
for (let i = 0; i < nums.length; i++) {
7+
for (let j = i + 1; j < nums.length; j++) {
8+
if (nums[i] + nums[j] === target) {
9+
return [i, j];
10+
}
11+
}
12+
}
13+
};
14+
15+
console.log(twoSum([2, 7, 11, 15], 9));

0 commit comments

Comments
 (0)