353. Expression Add Operators

Given a string num consisting of only digits and an integer target.Return all possibilities to insert the binary operators '+' , '*' , '-' between the digits of string nums, such that resultant expression evaluates to target value.

Note that operands in returned expression should not contain leading zeros.

Note that the given number can consist of multiple digits.

Example 1:

Input : num = "123", target = 6

Output : ["1*2*3" , "1+2+3"]

Explanation :

Both "1*2*3" and "1+2+3" evaluate to 6.

Example 2:

Input : num = "0232", target = 8

Output : ["0+2*3+2" , "0+2+3*2"]

Explanation :

Both "0+2*3+2" and "0+2+3*2" evaluate to 8.

Now Your Turn!

Pick the correct output for the given input

Input : num = "02", target = 0

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1<= num.length <= 10
  • num consist of only digits
  • -231 <= target <= 231 - 1

Fun Facts

0
class Solution {
public:
vector<string> addOperators(string s, int target) {
// Your code goes here
}
};
Test Case

Input:

Num
Target