1. Two Sum #1
Replies: 1 comment 1 reply
-
Solution based on hash table: class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
seen = {}
for i, value in enumerate(nums):
remaining = target - nums[i]
if remaining in seen:
return [i, seen[remaining]]
seen[value] = i |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
1. Two Sum
https://leetcode.com/problems/two-sum/
https://xjasonlyu.github.io/leetcode/1.two-sum/
Beta Was this translation helpful? Give feedback.
All reactions