Skip to content

Commit 668c07b

Browse files
committed
two sum solution
1 parent 202c175 commit 668c07b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

two-sum/hyer0705.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function twoSum(nums: number[], target: number): number[] {
2+
const numsLen = nums.length;
3+
const result: number[] = [];
4+
5+
for (let i = 0; i < numsLen - 1; i++) {
6+
for (let j = i + 1; j < numsLen; j++) {
7+
if (nums[i] + nums[j] === target) {
8+
result.push(i);
9+
result.push(j);
10+
break;
11+
}
12+
}
13+
}
14+
15+
return result;
16+
}

0 commit comments

Comments
 (0)