Math Fundamentals18 sections · 814 units
Open in Course

Two Sum - The Equation

What you're solving

You're solving nums[i]+nums[j]=targetnums[i] + nums[j] = target for indices ii and jj. Rearrange to see what you need:

nums[j]=targetnums[i]nums[j] = target - nums[i]

This tells you: for each number in the array, check if the complement (targetnums[i]target - nums[i]) exists elsewhere in the array. This algebraic rearrangement is the key insight.