Given a string expression of numbers and the operators +, - and *, return every result you can get by grouping the numbers and operators in all possible ways with parentheses. The answer may be returned in any order.
Given a string expression of numbers and the operators +, - and *, return every result you can get by grouping the numbers and operators in all possible ways with parentheses. The answer may be returned in any order.
Example 1:
Input: {"expression":"2-1-1"}
Output: [2,0]
Constraints:
1≤expression.length≤20
expression consists of digits and the operators +, - and *.
All integer values in the input expression are in the range [0,99].
The integer values in the input expression do not have a leading - or +.
The number of different results does not exceed 104, and every result fits in a 32-bit integer.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"expression":"2-1-1"}
2
last
-
last
1
last
-
last
1
last
Expression "2-1-1" has 2 operators. Every way to parenthesize picks one operator to apply last.