Question
Design and implement a TwoSum class. It should support the following operations: add and find.
add - Add the number to an internal data structure.
find - Find if there exists any pair of numbers which sum is equal to the value.
Explanation
和leetcode No.1一样,只是需要考虑的这里只能用一个不太需要维护的数据结构来存储,之前排序数组的那种方法就不可行了。同时要考虑计算frequency,会出现pair中两个数字是同一个的情况。