Two Sum
Brute Force

With brute force, we try every possible combination of numbers and aren’t particularly worried about runtime. It’s important to first just get a working solution and then optimize.

First we must set an empty array that we can later store our answers in. Within a double for loop, we use indexes i and j to get values within our array and see if they add up to the target sum value. If so, we push it to our answers array. Lastly, we return answers .

Looking at this in terms of runtime, this is probably the worst solution we could create — O(n²).
['Jack Tawil']
['Leetcode', 'Algorithms', 'JavaScript', 'Coding', 'Development']