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:
bool check(char a, char b){
if(a == '')
return true;
if(a == '' && b>= '' && b<= '')
return true;
return false;
}
int numDecodings(string s) {
int len = s.size();
if(len == || s[] == '') return ;
vector<int> res(len+,);
res[] = ;
res[] = ;
for(int i = ; i < len ; ++i){
if(s[i] == '' && (s[i-] == ||s[i-]>''))
return ;
if(s[i]<=''&& s[i] > '')
res[i+] = res[i];
if(check(s[i-], s[i]))
res[i+] += res[i-];
} return res[len];
}
};

LeetCode_Decode Ways的更多相关文章

  1. [LeetCode] Different Ways to Add Parentheses 添加括号的不同方式

    Given a string of numbers and operators, return all possible results from computing all the differen ...

  2. [LeetCode] Decode Ways 解码方法

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

  3. Decode Ways

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

  4. 【LeetCode】241. Different Ways to Add Parentheses

    Different Ways to Add Parentheses Given a string of numbers and operators, return all possible resul ...

  5. [Leetcode] Decode Ways

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

  6. Three ways to set specific DeviceFamily XAML Views in UWP

    Three ways to set specific DeviceFamily XAML Views in UWP http://igrali.com/2015/08/02/three-ways-to ...

  7. 241. Different Ways to Add Parentheses

    241. Different Ways to Add Parentheses https://leetcode.com/problems/different-ways-to-add-parenthes ...

  8. Different Ways to Add Parentheses

    Given a string of numbers and operators, return all possible results from computing all the differen ...

  9. 【leetcode】Decode Ways(medium)

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

随机推荐

  1. Iterator荟萃

    package com.starain.Iterator;/*代码整理快捷键为Ctrl+Shift+F * main方法输入快捷键main字符+Alt+/ * 输出快捷键sysout字符+Alt+/* ...

  2. Firefox中firebug和xpath checker工具的使用

    一直想把自己这段时间做的东西整理下,确迟迟没有动手,现在信息抽取工作已经做的差不多,把自己感觉很好用的两个工具介绍给大家吧!    Firefox真是一个好东西,它许多插件.本人是很讨厌插件的,每次电 ...

  3. 高性能MySql进化论(一):数据类型的优化_上

    在数据库的性能调优的过程中会涉及到很多的知识,包括字段的属性设置是否合适,索引的建立是否恰当,表结构涉及是否合理,数据库/操作系统 的设置是否正确…..其中每个topic可能都是一个领域. 在我看来, ...

  4. AsMVC:一个简单的MVC框架的Java实现

    当初看了<从零开始写一个Java Web框架>,也跟着写了一遍,但当时学艺不精,真正进脑子里的并不是很多,作者将依赖注入框架和MVC框架写在一起也给我造成了不小的困扰.最近刚好看了一遍sp ...

  5. [转] 浅谈 C++ 中的 new/delete 和 new[]/delete[]

    转:http://www.cnblogs.com/hazir/p/new_and_delete.html 在 C++ 中,你也许经常使用 new 和 delete 来动态申请和释放内存,但你可曾想过以 ...

  6. 固定textview大小,根据文字多少调整字体自适应textview大小

    /** * 文件名 AutoResizeTextView.java * 包含类名列表 com.haier.internet.conditioner.haierinternetconditioner2. ...

  7. 队列(链式存储)JAVA代码

      publicclassLinkQueue<T>{       //结点类     publicclassNode{         public T data;         pub ...

  8. LINQ Enumerable

    System.Linq.Enumerable类,提供了数十种称为扩展方法的共享方法,帮助您操作所有实现IEnumerable(of T)接口的类中的数据.由于Enumerable类的扩展方法可以处理许 ...

  9. div整体布局分析

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. ASP.Net中的编码与解码

    当javascript传递的参数中有中文时,服务端获得的将是乱码,此时需要用到编码和解码 javascript中编码与解码的三种方法 escape方法返回一个可在所有计算机上读取的编码 String ...