Here's the idea: instead of checking every pair, flip the question. For each number you see, ask "have I already seen my complement?"
Your complement is target - current_number. If it exists in your hash map, you found the pair. If not, store the current number and move on.
As you iterate, store each number's index in a map. When you reach 7 with target 9, you check: is 9-7=2 in the map? Yes, at index 0. Done.
You're building the map as you go. Each number gets one chance to find its complement among the numbers you've already seen. If no match, it becomes a potential complement for future numbers.