Decode Ways
来源:互联网 发布:厦门seo外包 编辑:程序博客网 时间:2024/06/02 12:52
题目描述为:
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.
int numDecodings(string s){if (s.empty())return 0;int n=s.size();vector<int> dp(n+1,0);dp[n]=1;int i=n-1;dp[i]=s[i]=='0'?0:1;for(i=n-2;i>=0;i--){if ( s[i]=='0' ){dp[i]=0;continue;}int tmp1=dp[i+1];int c=(s[i]-'0')*10+s[i+1]-'0';int tmp2=0;if ( c<=26 )tmp2=dp[i+2];dp[i]=tmp1+tmp2;}return dp[0];}
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode ways
- Decode Ways
- Decode Ways
- Decode Ways
- Decode Ways
- HTML基础(一):实用的CSS标签和属性值
- 栈的实现(JAVA)
- C++中bitset类的使用方法与应用
- .net listview 及 datalist 自动序号
- C++_运算符重载 http://blog.csdn.net/insistgogo/article/details/6626952
- Decode Ways
- 以德报怨
- poj 1182 食物链
- 多线程之互斥量mutex
- 8 Guys of JAVA
- 《我编程我快乐》读书笔记
- spring bean属性scope
- ubuntu开机启动(waiting for network configuration,……60 seconds more for……解决办法)
- SQL Server 2008/2012与JDBC完全配置