91. Decode Ways 数字转字母的不同编码方式
来源:互联网 发布:网络抓包软件debugger 编辑:程序博客网 时间:2024/06/13 23:27
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.
1. 看别人的 (这个我不会)
class Solution {public: bool isValid(char c){ return c <= '9' && c >'0'; } bool isvalid(char c1, char c2){ if(c1 == '1') return c2 <='9' && c2 >='0'; if(c1 == '2') return c2 <='6' && c2 >='0'; return false; } int numDecodings(string s) { int len = s.size(); if(len <= 0) return 0; vector<int>res(len+1,0); res[0] = 1; for(int i = 0; i < len; i++){ if(isValid(s[i])) res[i+1] += res[i]; if(isvalid(s[i-1],s[i])) res[i+1] += res[i-1]; } return res[len]; }};
0 0
- 91. Decode Ways 数字转字母的不同编码方式
- Decode Ways:数字的编码组合方式
- Decode Ways 编码的方式
- 动态规划——数字字符串转换为字母组合的种数(decode-ways)
- 数字转字母的编码方式的个数 ---- DP
- Decode Ways 不同的解码可能性
- 91. Decode Ways(解码方式)
- LeetCode 91 Decode Ways(编码方式)(*)
- Decode Ways 将数字转化为字母 动态规划 特殊情况处理(重)
- Leetcode 91. Decode Ways&&639.Decode ways
- 【Leetcode】Decode Ways 解码方式
- [Leetcode] 91. Decode Ways
- LeetCode --- 91. Decode Ways
- [LeetCode]91.Decode Ways
- [leetcode] 91.Decode Ways
- 91. Decode Ways
- Algorithms-91.Decode Ways
- [leetcode] 91. Decode Ways
- 单例模式
- 开源的人工神经网络计算库 FANN 学习笔记 1
- [LCA][CODEVS 2370]小机房的树
- java webservice 简单实例
- html复习第六天 京东首页布局(导航栏/左侧)
- 91. Decode Ways 数字转字母的不同编码方式
- World Wind Java 放大地球后变为黑色的解决办法
- 关于C++函数返回数组
- 二十、装饰设计模式
- scikit出现Reshape your data either using X.reshape(-1, 1) if your
- android 时间转换
- 关于多波束国产化的问题
- 周赛题
- Spring与Mybatis整合的MapperScannerConfigurer处理过程源码分析