# Question

Formatted question description: https://leetcode.ca/all/282.html

 282	Expression Add Operators

Given a string that contains only digits 0-9 and a target value,
return all possibilities to add binary operators (not unary) +, -, or * between the digits
so they evaluate to the target value.

Example 1:

Input: num = "123", target = 6
Output: ["1+2+3", "1*2*3"]

Example 2:

Input: num = "232", target = 8
Output: ["2*3+2", "2+3*2"]

Example 3:

Input: num = "105", target = 5
Output: ["1*0+5","10-5"]

Example 4:

Input: num = "00", target = 0
Output: ["0+0", "0-0", "0*0"]

Example 5:

Input: num = "3456237490", target = 9191
Output: []



# Algorithm

We need two variables diff and curNum, one is used to record the value to be changed, the other is the value after the current operation, and they all need to use long type, because the string is converted to int type, it is easy to overflow.

For addition and subtraction, diff is the negative value of the number to be added and the number to be subtracted.

For multiplication, it’s a bit more complicated, diff is the diff of the last change multiplied by the number to be multiplied.

For example, for example, 2+32, when the calculation is about to multiply by 2, the last cycle of curNum = 5, diff = 3, and if we want to calculate this multiplication by 2, the new change value diff should It is 32=6, and we need to remove the result of the previous +3 operation, and add a new diff, namely (5-3)+6=8, which is the value of the new expression 2+3*2.

Another thing to note is that if the input is “000”, 0, the following errors are prone to occur:

Wrong: ["0+0+0","0+0-0","0+0*0","0-0+0","0-0-0","0-0*0" ,"0*0+0","0*0-0","0*0*0","0+00","0-00","0*00","00+0"," 00-0","00*0","000"]

Correct:["0*0*0","0*0+0","0*0-0","0+0*0","0+0+0","0+0-0" ,"0-0*0","0-0+0","0-0-0"]


Java