91. Decode Ways (Array; DP)
A message containing letters from A-Z is being encoded to numbers using the following mapping:
'A' -> 1
'B' -> 2
...
'Z' -> 26
Given an encoded message containing digits, determine the total number of ways to decode it.
For example,
Given encoded message "12", it could be decoded as "AB" (1 2) or "L" (12).
The number of ways decoding "12" is 2.
class Solution {
public:
int numDecodings(string s) {
if(s.length()== || s[] == '') return ;
int* dp = new int [s.length()+];
dp[] = ;dp[]=;
for (int i = ; i < s.length(); i++)
{
if(s[i] == '')
{
if(s[i-] != '' && s[i-] != '') return ;
else dp[i+] = dp[i-];
}
else if(s[i-] == '' || (s[i] <= '' && s[i-] == ''))
{
dp[i+] = dp[i] + dp[i-];
}
else
dp[i+] = dp[i];
}
return dp[s.length()];
}
};
91. Decode Ways (Array; DP)的更多相关文章
- leetcode@ [91] Decode Ways (Dynamic Programming)
https://leetcode.com/problems/decode-ways/ A message containing letters from A-Z is being encoded to ...
- Leetcode 91. Decode Ways 解码方法(动态规划,字符串处理)
Leetcode 91. Decode Ways 解码方法(动态规划,字符串处理) 题目描述 一条报文包含字母A-Z,使用下面的字母-数字映射进行解码 'A' -> 1 'B' -> 2 ...
- 【LeetCode】91. Decode Ways 解题报告(Python)
[LeetCode]91. Decode Ways 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...
- [LeetCode] 91. Decode Ways 解码方法
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- 91. Decode Ways
题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: ' ...
- leetcode 91 Decode Ways I
令dp[i]为从0到i的总方法数,那么很容易得出dp[i]=dp[i-1]+dp[i-2], 即当我们以i为结尾的时候,可以将i单独作为一个字母decode (dp[i-1]),同时也可以将i和i-1 ...
- 91. Decode Ways反编译字符串
[抄题]: A message containing letters from A-Z is being encoded to numbers using the following mapping: ...
- [leetcode DP]91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- [leetcode]91. Decode Ways解码方法
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
随机推荐
- 正则的使用及replace细讲
1.var reg=/./ 与 var reg=/\./的区别? .代表任意一个字符 \.而后者代表这个字符串中得有一个. 2.?的使用 如果单独的一个字符后面带? /\d?/ 代表1个或0个这个字符 ...
- python simplejson and json 使用及区别
''' import simplejson as json #几个主要函数:dump.dumps.load.loads,带s跟不带s的区别: 带s的是对 字符串的处理,而不带 s的是对文件对像的处理. ...
- RouterOS 设定NAT loopback (Hairpin NAT)回流
In the below network topology a web server behind a router is on private IP address space, and the r ...
- [UE4]C++三种继承方式
(1) 公有继承(public) 公有继承的特点是基类的公有成员和保护成员作为派生类的成员时,它们都保持原有的状态,而基类的私有成员仍然是私有的,不能被这个派生类的子类所访问. (2)私有继承(pri ...
- PHPExcel导入导出 若在thinkPHP3.2中使用(无论实例还是静态调用(如new classname或classname::function)都必须加反斜杠,因3.2就命名空间,如/classname
php利用PHPExcel类导出导入Excel用法 来源: 时间:2013-09-05 19:26:56 阅读数: 分享到: 16 [导读] PHPExcel类是php一个excel表格处理插 ...
- iOS TTF文件改变字体
TTF(True Type Font):是一种字库名称 TTF文件:是Apple公司和Microsoft公司共同推出的字体文件格式 使用: 1 获取字体文件 从各种渠道下载字体ttf,网站或从别的ip ...
- Linux系统运行级与启动机制剖析
原文作者:技术成就梦想 原文链接:http://ixdba.blog.51cto.com/2895551/533740 一 系统运行级windows系统有安全运行模式和正常运行模式,这是两个不同的运行 ...
- TensorFlow系列专题(一):机器学习基础
- linux系统下修改文件夹目录权限-chmod
Linux.Fedora.Ubuntu修改文件.文件夹权限的方法差不多.很多人开始接触Linux时都很头痛Linux的文件权限问题.这里告诉大家如何修改Linux文件-文件夹权限.以主文件夹下的一个名 ...
- Mysql 开启Federated引擎以及使用
FEDERATED是其中一个专门针对远程数据库的实现.但通过FEDERATED引擎创建的表只是在本地有表定义文件,数据文件则存在于远程数据库中通过这个引擎可以实现类似Oracle 下DBLINK的远程 ...