Skip to content

Commit 0af9854

Browse files
committed
solve: twoSum
1 parent 26aa877 commit 0af9854

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

two-sum/b41-41.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// 1차 시도
2+
// function twoSum(nums: number[], target: number): number[] {
3+
// for(const index in nums) {
4+
// for(const index2 in nums) {
5+
// if (index !== index2) {
6+
// if(target === nums[index] + nums[index2]) {
7+
// return [Number(index), Number(index2)]
8+
// }
9+
// }
10+
// }
11+
// }
12+
// };
13+
14+
// 2차 시도
15+
function twoSum(nums: number[], target: number): number[] {
16+
for (const index in nums) {
17+
for (let index2 = Number(index) + 1; index2 < nums.length; index2++) {
18+
if(target === nums[index] + nums[index2]) {
19+
return [Number(index), Number(index2)]
20+
}
21+
}
22+
23+
}
24+
25+
return [];
26+
27+
};

0 commit comments

Comments
 (0)