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:
def numDecodings(self, s):
"""
:type s: str
:rtype: int
"""
if s=='':
return 0 dp = [0] *(len(s)+1)
dp[0] = 1
dp[1] = int(s[0]!='') for i in range(2,len(s)+1):
if(s[i-1]!=''):
dp[i]=dp[i-1] if s[i-2:i]>'' and s[i-2:i]<'':
dp[i] +=dp[i-2] return dp[len(s)]
## 1 2 1
## 1 0 1 #dp[i] = dp[i-1] if s[i] != "0"
# +dp[i-2] if "09" < s[i-1:i+1] < "27"

最新文章

  1. 100 个 Linux 常用命令大全
  2. Ubuntu13.04安装历险记--Mono,Nginx,Asp.Net一个都不能少
  3. 使用163CentOS镜像
  4. js自定义弹窗
  5. Yar - Yet Another RPC framework for PHP
  6. 转:2014 年 15 款新评定的最佳 PHP 框架
  7. Myeclipse普通工程转为Maven工程
  8. Spring——Web应用中的IoC容器创建(WebApplicationContext根应用上下文的创建过程)
  9. win10 uwp 绑定静态属性
  10. Linux入门命令解释(1)
  11. js介绍
  12. C博客作业01--分支,顺序结构
  13. JQuery 数组获取和删除元素
  14. 括号生成(Java实现)
  15. Linux查看日志常用命令
  16. 软工网络15团队作业4——Alpha阶段敏捷冲刺3.0
  17. python3 CERTIFICATE_VERIFY_FAILED错误 certificate verify failed
  18. SpringBoot添加对Log4j2的支持
  19. MySQL(视图、触发器、函数)
  20. 运维基础工具tmux介绍及使用

热门文章

  1. ios开发之--iOS 11适配:iOS11导航栏返回偏移
  2. 通过ArcGIS Desktop数据发布ArcGIS Server
  3. MYSQL IFNULL函数的使用
  4. [转载]SQL truncate 、delete与drop区别
  5. Tomcat在Linux下的安装与配置
  6. php检测文件只读、可写、可执行权限
  7. js中如何删除json对象的某一个选项
  8. Xcode模版生成文件头部注释
  9. github(其他类似github)下载到本地配置
  10. 微信小程序 --- 组件