LeetCode_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.
动态规划:
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的更多相关文章
- [LeetCode] Different Ways to Add Parentheses 添加括号的不同方式
Given a string of numbers and operators, return all possible results from computing all the differen ...
- [LeetCode] Decode Ways 解码方法
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- Decode Ways
https://leetcode.com/problems/decode-ways/ A message containing letters from A-Z is being encoded to ...
- 【LeetCode】241. Different Ways to Add Parentheses
Different Ways to Add Parentheses Given a string of numbers and operators, return all possible resul ...
- [Leetcode] Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- 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 ...
- 241. Different Ways to Add Parentheses
241. Different Ways to Add Parentheses https://leetcode.com/problems/different-ways-to-add-parenthes ...
- Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the differen ...
- 【leetcode】Decode Ways(medium)
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
随机推荐
- 男装电商Bonobos融资5500万美元,计划IPO,全靠体验店战略 - 国外 - 快鲤鱼
男装电商Bonobos融资5500万美元,计划IPO,全靠体验店战略 - 国外 - 快鲤鱼 男装电商Bonobos融资5500万美元,计划IPO,全靠体验店战略
- 禁止UITextField 使用粘贴复制功能
在开发中有时候会遇到这样的需求,就是一个文本框里面的内容不允许用户复制,或者不允许用户将其它地方复制的内容粘贴进来,本文交给你怎么实现禁止 UITextField 的粘贴.复制. 在 UITextFi ...
- JSP元素和标签
1.JSP 的运行原理 当服务器上的一个JSP 页面被第一次请求执行时,服务器上的JSP引擎首先将JSP 页面文件转译成一个java 文件,再将这个java 文件 编译生成字节码文件,然后通过执行字 ...
- Computer Vision and Machine Learning Competitions
一.ImageNet Object Detection, Object Classification+Localization 二.COCO Image Captioning 三.LFW Face R ...
- 重叠I/O之事件通知
在 Winsock 中,重叠 I/O(Overlapped I/O)模型能达到更佳的系统性能,高于select模型.异步选择和事件选择三种.重叠模型的基本设计原理便是让应用程序使 用一个重叠的数据 ...
- angular指令浅谈
今天在闲暇时间再次对angularjs的指令进行了初探,不探不知道一探吓一跳啊, 就一个简单的指令整整难住我了两个小时,先不说代码的逻辑是否复杂,就一些内部的一些实现让我看起来都是头疼的不行啊,不过最 ...
- MM32/STM32中断和事件梳理
Interrupt_event梳理 预备资料 MM32/stm32中文参考手册 Cortex-M3权威指南(深入了解中断和异常) MM32F103产品手册(配置GPIO的复用功能可能用到) 提出问题 ...
- 8、第八次课jquery第一节20151006
1.JS JQUERY 的区别 jquery 底层基于js 它是对于JS进行封装,代码量比较少.[write less do more] 网上可以下载jquery 类库文件,写的时候需要智能提示在js ...
- HTML5中class选择器属性的解释
设置有class属性值的元素,可以被css中的选择器调用,也可以在javascript中以getElementsByClassName()方法调用. 可以给各个元素添加class而且名称可以相同与id ...
- (转)用JS判断ckeditor3.6版本编辑器内容为空的方法
因为编者我还是一个初学入门者,无论是JS还是PHP,都是懂了点皮毛.今天在研究ckeditor编辑器的时候遇到了一些问题,虽然这只是我的个人问题,但觉得可以分享给其他人,或许也有像我这样的初学者也会遇 ...