This is a simple C++ program that demonstrates the Two Sum algorithm using the vector
container. The program takes an array of integers and a target sum as input and finds a pair of indices that correspond to two elements in the array whose sum equals the target.
The twoSum
function implements the Two Sum algorithm using nested loops to find the indices of two elements whose sum matches the target sum. If a solution is found, the function returns a vector
containing the indices of the two elements. If no solution is found, an empty vector
is returned.
- Clone this repository to your local machine.
- Navigate to the project directory.
- Compile the program using a C++ compiler (e.g., g++).
- Run the executable.
- Follow the on-screen prompts to input the array elements and target sum.
The twoSum
function iterates through the array using two nested loops. It checks each pair of elements to see if their sum matches the target sum. If a solution is found, the function returns a vector
containing the indices of the two elements.
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or create a pull request.
This project is licensed under the MIT License.