LeetCode - The Two Sum Part
This part is Two Sum related problems.
The key idea of Two Sum is to use HashMap to reduce search time. If we want to find a group of items in an array or a list, and these items has some properties which can be found if we know one of them. For example, the sum of two items is a constant value. The product of two items is a constant value.
Some related problems:
Analysis
The difference of 3Sum/4Sum and 2Sum is that we only have two items in 2Sum, so that we can just use a != b to remove duplicate collections. But if there are 3 items, we can not simply find out a solution to avoid duplicate triplets. So we need to sort them and use items of same value only once.