lintcode 解码方法
简单的动态规划
class Solution {
public:
/*
* @param s: a string, encoded message
* @return: an integer, the number of ways decoding
*/
int numDecodings(string s) {
// write your code here
if(s == "" || s[] == '') return ;
int dp[];
memset(dp, , sizeof(dp));
dp[] = ;
for(int i = ; i < s.length(); ++i){
if(s[i] == ''){
if(s[i - ] != '' && s[i -] != '') return ;
else {
dp[i] = dp[i] + (i - >= ? dp[i-] : );
}
} else {
if(s[i - ] == ''){
dp[i] = dp[i] + (i - >= ? dp[i-] : );
dp[i] = dp[i] + dp[i - ];
} else if(s[i - ] == ''){
if(s[i] <= '')
dp[i] = dp[i] + (i - >= ? dp[i-] : );
dp[i] = dp[i] + dp[i - ];
} else {
dp[i] = dp[i] + dp[i - ];
}
}
}
return dp[s.length() - ];
}
};
lintcode 解码方法的更多相关文章
- [LeetCode] Decode Ways 解码方法
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- C#中Base64之编码,解码方法
原文:C#中Base64之编码,解码方法 1.base64 to string string strPath = "aHR0cDovLzIwMy44MS4yOS40Njo1NTU3L1 ...
- [LeetCode] Decode Ways II 解码方法之二
A message containing letters from A-Z is being encoded to numbers using the following mapping way: ' ...
- [Swift]LeetCode91. 解码方法 | Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- [Swift]LeetCode639. 解码方法 2 | Decode Ways II
A message containing letters from A-Z is being encoded to numbers using the following mapping way: ' ...
- LeetCode(91):解码方法
Medium! 题目描述: 一条包含字母 A-Z 的消息通过以下方式进行了编码: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 给定一个只包含数字的非空字符串,请计 ...
- leetcode 91. 解码方法 JAVA
题目: 一条包含字母 A-Z 的消息通过以下方式进行了编码: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 给定一个只包含数字的非空字符串,请计算解码方法的总数. ...
- 使用多字节字符集的跨平台(PC、Android、IOS、WP)编码/解码方法
随着移动端的发展,跨平台已成为通讯架构设计的重要考虑因素,PC.Android.IOS.WP等跨多平台间的数据通讯,必然要解决字符编码/解码的问题. 多字节字符集MBCS不是跨平台的首选字符集,面向跨 ...
- LeetCode OJ:Decode Ways(解码方法)
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
随机推荐
- 1045 Favorite Color Stripe (30)(30 分)
Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor ...
- ACM学习历程—CSU 1216 异或最大值(xor && 贪心 && 字典树)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1216 题目大意是给了n个数,然后取出两个数,使得xor值最大. 首先暴力枚举是C(n, ...
- django TimedRotatingFileHandler log
15.9.6. TimedRotatingFileHandler¶ The TimedRotatingFileHandler class, located in the logging.handler ...
- CF1060B:Maximum Sum of Digits
我对贪心的理解:https://www.cnblogs.com/AKMer/p/9776293.html 题目传送门:http://codeforces.com/problemset/problem/ ...
- understanding of Pipe line & Timing Logic
///////////////////////////////////////////////////////////////////////////////// module vlg_add(inp ...
- CCS V5 使用教程三:程序调试
官网教程 新建调试工程 输入以下源码: #include <stdio.h> #include <c6x.h> ]; void main(void) { unsigned ; ...
- 【转】js中select的基本操作
判断select选项中 是否存在Value="paraValue"的Item // 1.判断select选项中 是否存在Value="paraValue"的I ...
- Random获取不重复随机数
Random R = new Random(Guid.NewGuid().GetHashCode()); int i = R.Next(9999);
- DevExpress 显示进度条
1.使用了DevExpress的WaitDialogForm WaitDialogForm waitDialogForm = null; new Thread((ThreadStart)delegat ...
- 5.SSRF服务器端请求伪造
SSRF(服务端请求伪造):是一种由攻击者构造形成由服务端发起请求的一个安全漏洞. 一般情况下,SSRF攻击的目标是从外网无法访问的内部系统.(正是因为它是由服务端发起的,所以它能够请求到与它相连而与 ...