第25天--算法(Leetcode 91)
作者:互联网
91.解码方法
public int numDecodings(String s) { char s1[] = s.toCharArray(); int N = s1.length; int dp[] = new int[N + 1]; dp[N] = 1; for(int index = N - 1;index >= 0;index --) { if(s1[index] == '0') { continue; } int ways = dp[index + 1]; if(index + 1 >= s1.length) { dp[index] = ways; continue; } int num = (s1[index] - '0') * 10 + s1[index + 1] - '0'; if(num <= 26) { ways += dp[index + 2]; } dp[index] = ways; } return dp[0]; }标签:25,index,--,s1,int,num,91,ways,dp 来源: https://www.cnblogs.com/study-Road/p/15839578.html