End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.
11DAYS
:
18HOURS
:
15MINUTES
:
01SECONDS
Leetcode Problem 1. Two Sum
1. Two Sum
Leetcode Solutions
One-pass Hash Table
Initialize an empty hash table (dictionary).
Iterate through the array of numbers.
a. For each element, calculate its complement by subtracting it from the target.
b. Check if the complement is present in the hash table.
i. If present, return the current index and the index of the complement from the hash table.
c. If the complement is not present, add the current element's value and index to the hash table.