147. Two Sum III - Data structure design
EasyDesign
Design a data structure that accepts a stream of integers and checks if it has a pair of integers that sum up to a particular value. Implement the `TwoSum` class: - `TwoSum()` Initializes the `TwoSum` object, with an empty array initially. - `void add(int number)` Adds `number` to the data structure. - `boolean find(int value)` Returns `true` if there exists any pair of numbers whose sum is equal to `value`, otherwise, it returns `false`.
Examples
Input: ["TwoSum","add","add","add","find","find"] [[],[1],[3],[5],[4],[7]]
Output: [null,null,null,null,true,false]
Explanation: find(4) matches 1+3; find(7) has no pair.
Constraints
- -10^5 <= number <= 10^5
- -2^31 <= value <= 2^31 - 1
- At most 10^4 calls will be made to add and find.
Loading...
Run checks all cases above. Submit evaluates all test cases.