Pair Sum β Unsorted
Given an unsorted array of integers nums and a target integer target, return true if there exist two numbers in the array that add up to the target.
Input: nums = [2, 7, 11, 15], target = 9
Output: true
function hasPairSum(nums, target) {
const seen = new Set();
for (const num of nums) {
if (seen.has(target - num)) return true;
seen.add(num);
}
return false;
}