leetcode-把数字翻译成字符串
基本思路
没看懂,动态规划,先做个记录
class Solution {
public int translateNum(int num) {
String str = String.valueOf(num);
int len = str.length();
if(len < 2) return len;
int[] dp = new int[len];
dp[0] = 1;
for(int i = 1;i<len;i++){
dp[i] = dp[i-1];
int temp = (str.charAt(i-1) - '0') * 10 + (str.charAt(i) - '0');
if(temp > 9 && temp <26){
if(i-2<0){
dp[i] = dp[i] + 1;
}else{
dp[i] += dp[i-2];
}
}
}
return dp[len-1];
}
}