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' - ...
随机推荐
- Flask+Mysql搭建网站之网页设计
不得不说,本人极度讨厌网页设计,感觉太麻烦了.不过整好啦还蛮有成就感的. 关于网页设计,现在流行的是扁平化设计. http://www.bootcss.com/ http://www.bootcss. ...
- Hat’s Words hdu-1247
就是查找这个单词能不能有两个单词组成,简单的字典树题目 ////////////////////////////////////////////////////////////// #include& ...
- SQL - 复制数据库中的一行
insert into MyTable(field1, field2, id_backup) select field1, field2, uniqueId from MyTable where un ...
- windows 编程 —— 菜单以及其他资源
目录: 1.资源的种类 2.资源的定义方法(IDE:VC++) 3.资源的获取 4.资源的使用与消息处理函数 1.资源的种类 windows 的常用的资源包括:图示 .游标. 字符串. 自订资源. ...
- DORIS-软件网址
DORIS下载网址:http://doris.tudelft.nl/ Doris软件最新的信息总可以在这个网址上查到:http://enterprise.tudelft.nl/doris/
- [Javascript] Advanced Reduce: Common Mistakes
Take away: Always check you ruturn the accumulator Always pass in the inital value var data = [" ...
- SpannableString的一个奇怪的问题
今天使用spannableString遇到一个奇怪的问题,就是在setspan的时候,原本可以写成 spannableString.setSpan(new RelativeSizeSpan(0.5f) ...
- 2015 UESTC Winter Training #7【2010-2011 Petrozavodsk Winter Training Camp, Saratov State U Contest】
2015 UESTC Winter Training #7 2010-2011 Petrozavodsk Winter Training Camp, Saratov State U Contest 据 ...
- JAVA小项目之五子棋
五子棋V1.0 功能: 人人对战,人机对战(初级) 记录双方分数: 主要知识点: 二维坐标系中,各方向坐标的关系及规律. 效果图: 主框架类: package com.gxlee.wzq; /** * ...
- sql Server 常用存储过程的优化
优化存储过程有很多种方法,下面介绍最常用的7种. 1.使用SET NOCOUNT ON选项 我们使用SELECT语句时,除了返回对应的结果集外,还会返回相应的影响行数.使用SET NOCOUNT ON ...