Practice/LinkedIn/Leetcode 282. Expression Add Operators
CodingMust
You are given a string containing only digits and an integer target value. Your task is to insert the binary operators +, -, and * between the digits to create valid mathematical expressions that evaluate to the target value. Return all possible expressions that evaluate to the target.
You can form multi-digit numbers by not placing an operator between consecutive digits. However, you must not create numbers with leading zeros (e.g., "05" is invalid, but "0" alone is valid).
The operators follow standard mathematical precedence where multiplication is evaluated before addition and subtraction.
Example 1:
` Input: num = "123", target = 6 Output: ["1+2+3", "123"] Explanation:
Example 2:
` Input: num = "232", target = 8 Output: ["23+2", "2+32"] Explanation:
Example 3:
` Input: num = "105", target = 5 Output: ["1*0+5", "10-5"] Explanation:
Example 4:
Input: num = "00", target = 0 Output: ["0+0", "0-0", "0*0"] Explanation: All three expressions evaluate to 0.