← 返回 meta 的题目列表Expression Add Operators to Reach Target
类型:online_judge
meta
Given a string num that contains only digits and an integer target, return all possibilities for inserting the binary operators +, -, and * between the digits in num such that the expressions evaluate to the target value. Do not include leading zeros in the expressions.
Input:
num: A string containing only digits
target: An integer
Output:
A list of valid expressions that evaluate to the target value
Example:
Input: num = "123", target = 6
Output: ["1+2+3", "1*2*3"]
Constraints:
1 <= num.length <= 10
num contains only digits
-2^31 <= target <= 2^31 - 1
Example
Input
num = "123", target = 6