Skip to content

Commit

Permalink
add: two-sum
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrineKim committed Dec 27, 2024
1 parent 4c8b68f commit a148775
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions two-sum/HerrineKim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 시간 복잡도 : O(n)
// 공간 복잡도 : O(n)

/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
let numMap = new Map();

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

if (numMap.has(complement)) {
return [numMap.get(complement), i];
}

numMap.set(nums[i], i);
}
};

0 comments on commit a148775

Please sign in to comment.