Title: #1 - Two Sum - LeetCode JavaScript Solutions
Open Graph Title: #1 - Two Sum - LeetCode JavaScript Solutions
X Title: #1 - Two Sum - LeetCode JavaScript Solutions
Description: Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`. You may assu...
Open Graph Description: Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`. You may assu...
X Description: Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`. You may assu...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/two-sum
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/two-sum","name":"#1 - Two Sum - LeetCode JavaScript Solutions","description":"Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`. You may assu...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[]}\n */\nvar twoSum = function(nums, target) {\n const map = new Map();\n\n for (let i = 0; i < nums.length; i++) {\n const diff = target - nums[i];\n\n if (map.has(diff)) {\n return [map.get(diff), i];\n }\n\n map.set(nums[i], i);\n }\n};","keywords":"LeetCode 1, #1 - Two Sum, Easy, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/two-sum |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/two-sum/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0001-two-sum.js |
| Array | https://leetcodejavascript.com/tags/array |
| Hash Table | https://leetcodejavascript.com/tags/hash-table |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow