- This is a
backtrackingproblem, very similar to
- We need to record
sum, so we can check if we’ve got the result quickly.
prev = cur,
sum += cur
prev = -cur,
sum -= cur.
sum = (sum - prev) + cur*prevas in
(7 - 2*3) + 4*2*3.
prev = prev*cur.
Given a string num that contains only digits and an integer target, return
all possibilities to insert the binary operators ‘+’, ‘-‘, and/or ‘*’ between the digits of num so that the resultant expression evaluates to the target value.
Note that operands in the returned expressions
should not contain leading zeros.
Input: num = "105", target = 5