Two Sum III - Data structure design
Explore how to design a custom data structure that stores a stream of numbers and efficiently checks if any two numbers add up to a given value. This lesson helps you implement the TwoSum class with methods to add numbers and find specific sums, enhancing problem-solving skills with data structures.
We'll cover the following...
We'll cover the following...
Statement
Design a data structure that takes in a stream of numbers and can check if any two numbers add up to a specific value.
Implement the TwoSum class with the following constructor and methods:
Constructor: Sets up the
TwoSumobject with an empty list at the start.void add(int number): Adds a new number to the list.
boolean find(int value): Returns TRUE if any two numbers in the list add up to the given value. If not, it returns FALSE.
Constraints:
...