Skip to content

Commit

Permalink
Merge pull request #799 from nakjun12/main
Browse files Browse the repository at this point in the history
[nakjun12] Week 3
  • Loading branch information
SamTheKorean authored Dec 29, 2024
2 parents 4cf7b2c + 00b6cde commit d754bb7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions two-sum/nakjun12.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* TC: O(n)
* SC: O(n)
* */
function twoSum(nums: number[], target: number): number[] {
const indices = {};

for (let i = 0; i < nums.length; i++) {
const curNum = nums[i];
const complement = target - curNum;

if (complement in indices) {
return [indices[complement], i];
}

indices[curNum] = i;
}

return [];
}

0 comments on commit d754bb7

Please sign in to comment.