// 递归
class Solution {
public List<Integer> diffWaysToCompute(String expression) {
if(expression==null ||expression.length()==0){
return new ArrayList<>();
}
List<Integer> ans=new ArrayList<>();
char[] chars=expression.toCharArray();
for(int i=0;i<chars.length;i++){
char op=chars[i];
if(!Character.isDigit(chars[i])){
String str1=expression.substring(0,i);
String str2=expression.substring(i+1);
List<Integer> leftList=diffWaysToCompute(str1);
List<Integer> rightList=diffWaysToCompute(str2);
for(int l:leftList){
for(int r:rightList){
if(op=='+'){
ans.add(l+r);
}else if(op=='-'){
ans.add(l-r);
}else {
ans.add(l*r);
}
}
}
}
}
if(ans.isEmpty()){
ans.add(Integer.valueOf(expression));
}
return ans;
}
}