https://leetcode.com/problems/decode-ways/

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.

类似于爬梯子,对于第i位,其解码方式可能为:

1)如果该位不为0,则可以继续按照i-1位的方式解码

2)如果该位和前一位的值在10和26之间,则可继续按照i-2位的方式解码

class Solution {
public:
int numDecodings(string s) { if(s.empty())return ;
int len=s.size();
vector<int> num(len+,);
num[]=; for(int i=;i<=len;i++)
{
if(s[i-]!='')
num[i]+=num[i-];
if(i>= && s.substr(i-,)>="" && s.substr(i-,)<="")
num[i]+=num[i-];
} return num.back();
}
};

Decode Ways的更多相关文章

  1. [LeetCode] Decode Ways 解码方法

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

  2. [LintCode] Decode Ways 解码方法

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

  3. 44. Decode Ways && Gray Code

    Decode Ways A message containing letters from A-Z is being encoded to numbers using the following ma ...

  4. 91. Decode Ways

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

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

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

  6. leetcode面试准备:Decode Ways

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

  7. [LeetCode] Decode Ways II 解码方法之二

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

  8. leetcode 639 Decode Ways II

    首先回顾一下decode ways I 的做法:链接 分情况讨论 if s[i]=='*' 考虑s[i]单独decode,由于s[i]肯定不会为0,因此我们可以放心的dp+=dp1 再考虑s[i-1] ...

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

  10. Decode Ways leetcode java

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

随机推荐

  1. [LeetCode] Design Hit Counter 设计点击计数器

    Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...

  2. [LeetCode] Best Time to Buy and Sell Stock with Cooldown 买股票的最佳时间含冷冻期

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  3. [LeetCode] Longest Valid Parentheses 最长有效括号

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  4. 【URAL 1519】Formula 1

    http://acm.timus.ru/problem.aspx?space=1&num=1519 调了好久啊.参考(抄)的iwtwiioi的题解. 如果想要题解,题解在<基于连通性状态 ...

  5. [转]如何循序渐进向dotnet架构师发展

    微软的DotNet开发绝对是属于那种入门容易提高难的技术.而要能够成为DotNet架构师没有三年或更长时间的编码积累基本上是不可能的.特别是在大 型软件项目中,架构师是项目核心成员,承上启下,因此RU ...

  6. PL/SQL数据库,Oracle登录

    用户名:TESTZYPX_9999 数据库:10.75.142.242:1521/orcl

  7. cocoapods安装

    什么是cocoapods CocoaPods是一个用来帮助我们管理第三方依赖库的工具.它可以解决库与库之间的依赖关系,下载库的源代码,同时通过创建一个Xcode的workspace来将这些第三方库和我 ...

  8. jquery的几种ajax提交方式

    $.post( url, function(data){ if(data.retcode == "0"){ alert(data.retmsg); }else{ alert(dat ...

  9. FFT 快速傅里叶变换浅析

    终于补完坑了哈哈哈 这个东西很神奇,看了半天网上的解释和课件,研究了很长时间,算是大概明白了它的原理. 话不多说先上图. 我们要求的h(x)=f(x)*g(x),f(x)=Σai*x^i,g(x)=Σ ...

  10. git的详细说明文档

    http://www.ihref.com/read-16369.html fork 后如何保持同步 http://www.tuicool.com/articles/6vayqen git clone ...