Skip to content

Commit 5534d22

Browse files
committed
two some solution
1 parent 609e3c7 commit 5534d22

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

two-sum/robinyoon-dev.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} target
4+
* @return {number[]}
5+
*/
6+
var twoSum = function (nums, target) {
7+
for (let i = 0; i < nums.length; i++) {
8+
let remaindedNum = target - nums[i];
9+
let matchedNum = nums.find((item) => remaindedNum === item);
10+
let matchedNumIndex = nums.indexOf(matchedNum, i + 1);
11+
// i와 matchedNumIndex 이 같은 숫자면 안 됨.
12+
if (i === matchedNumIndex) {
13+
continue;
14+
} else if (matchedNumIndex === -1) {
15+
continue;
16+
}
17+
else {
18+
return [i, matchedNumIndex];
19+
}
20+
}
21+
};

0 commit comments

Comments
 (0)