Skip to content

Commit 320cd1c

Browse files
committed
feat: two-sum solution
1 parent 4c8b68f commit 320cd1c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

two-sum/YeomChaeeun.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 배열 두 수의 합이 target 과 같은 값
3+
* 알고리즘 복잡도:
4+
* - 시간복잡도: O(n^2)
5+
* - 공간복잡도: O(1)
6+
* @param nums
7+
* @param target
8+
*/
9+
function twoSum(nums: number[], target: number): number[] {
10+
let result: number[] = [];
11+
12+
for(let i = 0; i < nums.length; i++) {
13+
for(let j = i + 1; j < nums.length; j++) {
14+
if(nums[i] + nums[j] === target) {
15+
result.push(i, j);
16+
return result;
17+
}
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)