Skip to content

Commit 25f0b86

Browse files
committed
s: two-sum
1 parent 0fc7ec8 commit 25f0b86

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

two-sum/dev-qorh.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 가장 단순한 O(n^2) 로 풀이하였습니다
3+
*/
4+
function twoSum(nums: number[], target: number): number[] {
5+
let temp_i = 0;
6+
let temp_j = 0;
7+
8+
for (let i = 0; i < nums.length; i++) {
9+
temp_i = nums[i];
10+
for (let j = i + 1; j < nums.length; j++) {
11+
temp_j = nums[j];
12+
13+
if (temp_i + temp_j === target) {
14+
return [i, j];
15+
}
16+
}
17+
}
18+
19+
return [];
20+
}

0 commit comments

Comments
 (0)