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' - ...
随机推荐
- M - Escape - HDU 3605 - (缩点+最大流SAP)
题目大意:2012世界末日来了,科学家发现了一些星球可以转移人口,不过有的人可以在一些星球上生存有的人不行,而且每个星球都有一定的承载量,现在想知道是否所有的人都可以安全转移呢? 输入:首先输入一个N ...
- Hdu 1856(离散化+并查集)More is better
题意:一些人遵循朋友的朋友也是朋友原则,现在找出最大的朋友圈, 因为人的编号比较大,但是输入的数据最多是10w行,所以可得出最多也就20w人,所以可以进行一下离散化处理,这样数据就会毫无压力 //// ...
- WKWebview点击图片查看大图
大家都知道,WKWebview是没有查看大图的属性或者方法的,所以只能通过js与之交互来实现这一功能,原理:通过js获取页面的图片,把它存放到数组,给图片添加点击事件,通过index显示大图就行了 其 ...
- Max retries exceeded with ur
requests模块在抓取网页时抛出ConnectionError异常,Max retries exceeded with url 主要搜下 "Caused by <class 'so ...
- 使用truncate命令清空当前用户所有表的所有数据
--批量清空当前用户所有表的所有数据 declarev_sql varchar2(2000) ;CURSOR cur is select table_name from user_tables ord ...
- 去掉app右侧滑动时出现的滚动条
把plus.webview.currentWebview().setStyle({scrollIndicator:'none'});放在mui.plusReady({});内
- jdbc03 使用servlet实现
<%@page import="cn.bdqn.bean.News"%> <%@page import="cn.bdqn.service.impl.Ne ...
- css04使用外部样式
1.创建一个新的html页面 <!DOCTYPE html> <html> <head lang="en"> <meta charset= ...
- 《photoshop cc 新功能 生成图像资源》智能切图逆天啦!
作为一个前端工程师切图这个步骤是必不可少的,方式多种多样,有和切图工具的,也有是把要切的图层元素或者组直接新建保存成文件的,现在photoshop cc2015,可以让你轻松切图,摆脱繁琐的切图步骤. ...
- Arcgis Android 基本概念 - 浅谈
MapView MapView 是 Android 中 ViewGroup的子类,也是 ArcGIS Runtime SDK for Android 中的地图容器,与很多 ArcGIS API ...