LeetCode Explained: 1 Two Sum

In this question, we are given an array of integer nums and an integer target, and we are asked to return two distinct indices such that the numbers in those positions add up to be the target. The question assumes that there is one and only one solution for each input.

Approach 1: Brute Force

Traverse the array. For each number num in the array, traverse the rest of the array to see if target - num can be found.

For example: