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.

DP,方法感觉有点像Fobinacci

 class Solution(object):
def numDecodings(self, s):
if s=='' or s[0]=='': return 0
r1,r2 = 1,1
for i in range(1,len(s)):
if s[i] == '':
r1 = 0
if s[i-1:i+1]<'':
r1,r2 = r1+r2,r1
else:
r2= r1
return r1

[leetcode DP]91. Decode Ways的更多相关文章

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

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

  2. 【一天一道LeetCode】#91. Decode Ways

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 A messa ...

  3. 【LeetCode】91. Decode Ways

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

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

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

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

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

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

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

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

  8. 91. Decode Ways

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

  9. leetcode面试准备:Decode Ways

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

随机推荐

  1. Linux学习4-信号

      信号 信号是Unix和Linux系统响应某些条件而产生的一个条件.接收到该信号的进程会相应的采取一些行动. 信号是由于某些错误条件而生成的,如内存冲突,浮点处理器错误或非法指令等.它们由shell ...

  2. HDU 1535 Invitation Cards (最短路)

    题目链接 Problem Description In the age of television, not many people attend theater performances. Anti ...

  3. 字符串hash&&对字符串hash的理解

     对字符串hash的一些总结: 1,首先,我们在转化的时候,取底的时候一般是取131这些数,因为要避免不同的字符串对应相同的hash值这种情况的出现.如果卡精度的时候,我们可以采取双模数的方式尽量减少 ...

  4. aarch64_n1

    NFStest-2.1.5-0.fc26.noarch.rpm 2017-02-17 01:19 531K fedora Mirroring Project NLopt-2.4.2-11.fc26.a ...

  5. rsync本地及远程复制备份【原创】

    1.安装rsyncyum instsall rsync 2.本地复制 rsync -auq --progress --delete /tongbu1/ /tongbu2/ rsync -auq --p ...

  6. openstack发展历程及其架构简介

    1.0 Openstack介绍 OpenStack既是一个社区,也是一个项目和一个开源软件,它提供了一个部署云的操作平台或工具集.其宗旨在于,帮助组织运行为虚拟计算或存储服务的云,为公有云.私有云,也 ...

  7. Visual Studio 2017 for Mac

    Visual Studio 2017 for Mac Last Update: 2017/6/16 我们非常荣幸地宣布 Visual Studio 2017 for Mac 现已推出. Visual ...

  8. SQLite数据库初步

    Windows 10家庭中文版 想使用Python操作SQLite数据库,可是,不知道怎么建立数据库文件. 在SQLite官网溜达了一圈,总算使用上面的工具安装了建立了我需要的数据库文件. 1.进入官 ...

  9. ASP.NET MVC5 支持PUT 和DELETE

    Web.config <configuration> <system.webServer> <handlers> <remove name="Ext ...

  10. Python 模块进阶

    import导入模块 1. import 搜索路径 import sys sys.path 例子: In [1]: import sys In [2]: sys.path Out[2]: ['', ' ...