Leetcode 1. Two Sum

sateesh.py
Nov 12, 2023

--

class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
hashmap = {}
for index,value in enumerate(nums):
diff = target - value
if diff in hashmap:
return [hashmap[diff],index]
else:
hashmap[value] = index

from this problem, i learned how to use HashMap

--

--

sateesh.py
sateesh.py

Written by sateesh.py

Python & data enthusiast | Helping businesses extract insights from their data | Experienced in Python, SQL, and data visualization

No responses yet