题目描述
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +
, -
and *
.
Example 1:
1 | Input: "2-1-1" |
Example 2:
1 | Input: "2*3-4*5" |
这题需要使用分治法。比如对于2*3-4*5,可以根据操作符来进行分治,比如根据’-‘可以分成2*3和4*5,然后再算每一个小块的所有可能值,最后用’-‘在所有可能值之间进行减法操作。
1 | class Solution { |