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)的更多相关文章

  1. leetcode@ [91] Decode Ways (Dynamic Programming)

    https://leetcode.com/problems/decode-ways/ A message containing letters from A-Z is being encoded to ...

  2. Leetcode 91. Decode Ways 解码方法(动态规划,字符串处理)

    Leetcode 91. Decode Ways 解码方法(动态规划,字符串处理) 题目描述 一条报文包含字母A-Z,使用下面的字母-数字映射进行解码 'A' -> 1 'B' -> 2 ...

  3. 【LeetCode】91. Decode Ways 解题报告(Python)

    [LeetCode]91. Decode Ways 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...

  4. [LeetCode] 91. Decode Ways 解码方法

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  5. 91. Decode Ways

    题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: ' ...

  6. 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 ...

  7. 91. Decode Ways反编译字符串

    [抄题]: A message containing letters from A-Z is being encoded to numbers using the following mapping: ...

  8. [leetcode DP]91. Decode Ways

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  9. [leetcode]91. Decode Ways解码方法

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

随机推荐

  1. 操作系统-百科:Kylin (中国自主知识产权操作系统)

    ylbtech-操作系统-百科:Kylin (中国自主知识产权操作系统) Kylin操作系统是国家高技术研究发展计划(863计划)的重大成果之一,是以国防科技大学为主导,与中软.联想等单位联合设计和开 ...

  2. Neuromation新研究:利用卷积神经网络进行儿童骨龄评估

    近日,Neuromation 团队在 Medium 上撰文介绍其最新研究成果:利用卷积神经网络(CNN)评估儿童骨龄,这一自动骨龄评估系统可以得到与放射科专家相似或更好的结果.该团队评估了手骨不同区域 ...

  3. [Python] Scipy and Numpy(1)

    import numpy as np #Create an array of 1*10^7 elements arr = np.arange(1e7) #Converting ndarray to l ...

  4. js实现复选框的全选和全不选

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  5. vb 水晶报表打印

    vb里面的水晶报表打印控件:CrystalReportViewer 用到的dll文件: 水晶报表打印其实很简单,只要创建报表对象,再对其传递数据就可以打印出来.当然所传递的数据要与水晶报表设计里面的数 ...

  6. Servlet、Servlet容器等内容讲解

    转载自http://blog.csdn.net/iAm333 对于Servlet.Servlet容器以及一个Servlet容器-Tomcat这些概念讲解的挺清晰的,转载下 之前在开源中国看到一篇文章& ...

  7. os模块和sys模块,以及random模块

    os模块 os模块是与操作系统交互的一个接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工 ...

  8. Spring MVC 学习笔记1 - First Helloworld by Eclipse【& - java web 开发Tips集锦】

    Spring MVC 学习笔记1 - First Helloworld by Eclipse reference:http://www.gontu.org 1. 下载 Spring freamwork ...

  9. Java的Guava

    主要是看代码看到了Table这个类,竟然有两个键! http://www.cnblogs.com/peida/p/3183505.html

  10. Spring-boot+Mybatis+Maven+MySql搭建实例

    转自:https://www.jianshu.com/p/95fb7be049ae 最近读了spring-boot开发手册,spring-boot相比于spring-mvc封装了很多常用的依赖,并且内 ...