282. Expression Add Operators
Problem description:
Given a string num
that contains only digits and an integer target
, return all possibilities to add the binary operators '+'
, '-'
, or '*'
between the digits of num
so that the resultant expression evaluates to the target
value.
Example 1:
1 | Input: num = "123", target = 6 |
Example 2:
1 | Input: num = "232", target = 8 |
Example 3:
1 | Input: num = "105", target = 5 |
Example 4:
1 | Input: num = "00", target = 0 |
Example 5:
1 | Input: num = "3456237490", target = 9191 |
Constraints:
1 <= num.length <= 10
num
consists of only digits.231 <= target <= 231 - 1
Solution:
1 | class Solution: |
time complexity: $O(3^n)$
space complexity: $O()$
reference:
related problem: