Skip to content

Commit 15bcd5a

Browse files
committed
feat: Two Sum
1 parent da5ef70 commit 15bcd5a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
# leetcode-blind-75-javascript
1+
# LeetCode Blind 75 Problems in JavaScript
2+
23
Solutions of LeetCode Blind 75 Problems in JavaScript
4+
5+
:goal_net: [Curated List of Top 75 LeetCode Questions](https://www.teamblind.com/post/New-Year-Gift---Curated-List-of-Top-75-LeetCode-Questions-to-Save-Your-Time-OaM1orEU)
6+
7+
| Problem | Difficulty | Tags | LeetCode |
8+
| ----------------------- | ------------------------------------------------------ | --------------------- | ------------------------------------------------ |
9+
| [Two Sum](./two-sum.js) | <img src="https://img.shields.io/badge/-Easy-green" /> | `Array`, `Hash Table` | [:link:](https://leetcode.com/problems/two-sum/) |

two-sum.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const twoSum = (nums, target) => {
2+
const indexMap = {};
3+
4+
for (let i = 0; i < nums.length; i++) {
5+
const num = nums[i];
6+
const consolidated = target - num;
7+
8+
if (consolidated in indexMap) {
9+
return [indexMap[consolidated], i];
10+
}
11+
indexMap[num] = i;
12+
}
13+
};

0 commit comments

Comments
 (0)