2017.10.24
当遍历到s的第i个字符时 d[i] = max(i*d[i-1], i+ d[i-1])
public class Solution {
/*
* @param : the given string
* @return: the maximum value
*/
public int calcMaxValue(String str) {
// write your code here
if(str.length() == 0){
return 0;
}
if(str.length() == 1){
return Integer.valueOf(str);
}
int a = Integer.valueOf(str.substring(0,1));
int b = Integer.valueOf(str.substring(1,2));
int res = Math.max(a+b, b*a);
if(str.length() == 2){
return res;
}
for(int i = 2; i < str.length(); i++){
int tmp = Integer.valueOf(str.substring(i,i+1));
//System.out.print("tmp = " + tmp + ";旧res = " + res);
res = Math.max(tmp+res, tmp*res);
//System.out.println(";新res = " + res);
}
return res;
}
};