← 返回 netflix 的题目列表Number Pairs That Match Target
类型:qbank
Return every distinct expression string "a{op}b" from a list where one of +,-,*,/ yields the target (order matters, integer-only division, no divide-by-zero, dedupe identical strings).
Problem Statement
You are provided with a list of integers called nums and a specific number called target. You need to find all pairs of numbers from the list that result in target when you perform one of the four basic math operations: addition (+), subtraction (-), multiplication (*), or division (/).
For every valid pair (a, b) that equals the target, you must return a string formatted like "a{op}b". For example: "2+4" or "3*2".
Rules:
Order counts: "2+4" and "4+2" are treated as two different pairs if they both equal the target.
Division rules: Only count division if it divides evenly (no remainder). You cannot divide by zero.
Indices must differ: You must use numbers from different positions in the list. If the same number appears more than once, treat each one as a separate item.
Unique strings: If the same expression string is created by different pairs of indices, include that string only once in your final list.
You can return the list of strings in any order.
Sample Cases
Case 1:
Input: nums = [2, 4, 6, 3], target = 6
Output: ["2+4", "4+2", "2*3", "3*2"]
Explanation:
2 + 4 = 6
4 + 2 = 6
2 * 3 = 6
3 * 2 = 6
Case 2:
Input: nums = [1, 2, 3, 4], target = 2
Output: ["1*2", "2*1", "2/1", "4/2", "3-1", "4-2"]
Explanation:
1 * 2 = 2
2 * 1 = 2
2 / 1 = 2
4 / 2 = 2
3 - 1 = 2
4 - 2 = 2
Case 3:
Input: nums = [5, 10, 2], target = 5
Output: ["10/2", "10-5"]
Explanation:
10 / 2 = 5
10 - 5 = 5
Input Limits
2 <= nums.length <= 100
-1000 <= nums[i] <= 1000
-10000 <= target <= 10000