Given an array of integers nums and a target integer target, count the number of pairs (i, j) where i < j such that nums[i] + nums[j] == target.
Use a brute-force nested loop approach: check every possible pair.
For example, given nums = [1, 2, 3, 4, 5] and target = 5, the valid pairs are (0, 3) giving 1 + 4 = 5 and (1, 2) giving 2 + 3 = 5, so the answer is 2.
nums = [1, 2, 3, 4, 5], target = 52nums = [1, 1, 1], target = 23nums = [1, 2, 3], target = 1002 <= nums.length <= 1000-10^6 <= nums[i] <= 10^6-10^6 <= target <= 10^6Run your code to see results
Use Cmd+Enter to run