首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
解密
[编程题]解密
热度指数:22010
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32M,其他语言64M
算法知识视频讲解
一条仅包含字母‘A’-‘Z’的消息用下列的方式加密成数字
'A' -> 1 'B' -> 2 ... 'Z' -> 26
现在给出加密成数字的密文,请判断有多少种解密的方法
例如:
给出的密文为“13”,可以解密为
"AC"(1 3) 或者"M"(13).
所以密文
"13"的解密方法是2种.
示例1
输入
"1"
输出
1
示例2
输入
"13"
输出
2
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(3)
邀请回答
收藏(93)
分享
提交结果有问题?
66个回答
2篇题解
开通博客
you_config
发表于 2025-04-29 01:47:08
class Solution: def numDecodings(self , s ): # write code here if s == '' or s[0] == '0': return 0 dp = [1]*(l
展开全文
华科不平凡
发表于 2020-08-11 11:13:19
这个动态规划有点难,因为f(i)不仅与f(i-1)有关,和f(i-2)也有关系,能想明白这一层关系着实不容易0.0 设当前的解法有f(i)种,由于s[i]和s[i - 1]的搭配方式有多种,下面分情况讨论: 非法的情况,即不论怎么搭配都decode不了,返回0 合法的情况,如果只能搭配成一种,那么
展开全文
问题信息
动态规划
难度:
66条回答
93收藏
19410浏览
热门推荐
通过挑战的用户
查看代码
落霞与孤鹜齐飞ccc
2022-09-10 16:06:46
Varus20...
2022-08-21 12:45:06
GoodLuc...
2022-08-04 13:35:57
DamonGuan
2022-07-14 23:29:55
相关试题
自由落体
数学
NOIP复赛
评论
(2)
牛牛学数列5
过关题目
语言题
评论
(2)
牛牛学数列6
过关题目
语言题
评论
(1)
下列关于alpha、beta 测试...
软件测试
评论
(2)
使用梯度下降的线性回归
机器学习
评论
(1)
解密
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * * @param s string字符串 * @return int整型 */ public int numDecodings (String s) { // write code here } }
class Solution { public: /** * * @param s string字符串 * @return int整型 */ int numDecodings(string s) { // write code here } };
# # # @param s string字符串 # @return int整型 # class Solution: def numDecodings(self , s ): # write code here
/** * * @param s string字符串 * @return int整型 */ function numDecodings( s ) { // write code here } module.exports = { numDecodings : numDecodings };
# # # @param s string字符串 # @return int整型 # class Solution: def numDecodings(self , s ): # write code here
package main /** * * @param s string字符串 * @return int整型 */ func numDecodings( s string ) int { // write code here }
"1"
1
"13"
2