Skip to content

Instantly share code, notes, and snippets.

View Tech-sis123's full-sized avatar

Blessing is a ticking time bomb! Tech-sis123

View GitHub Profile
@Tech-sis123
Tech-sis123 / twoSum.py
Created January 6, 2026 13:47
This is an implementation of the Two Sum problem, where the goal is to find two numbers in an array that add up to a specific target value. The solution uses a hash map (dictionary) to store the indices of numbers as they are encountered, allowing us to efficiently check if the complement (target - current number) has already been seen in the ar…
def twoSum(num, target):
num_map = {}
for i, n in enumerate(num):
complement = target - n
if complement in num_map:
return [complement, num[i]]
num_map[n] = i
return [];