当前位置:网站首页>leetcode:91. Decoding method [DFS + memorization]
leetcode:91. Decoding method [DFS + memorization]
2022-06-29 22:18:00 【Review of the white speed Dragon King】

analysis
dfs(s) Express this s How many different solutions can be generated
First, if it's empty , It must be a solution
A leading 0 unsolvable
There is only one ( Non leading 0) A solution
then res Record answer
First plus dfs(s[1:]) First position ok
Then judge s[:2] Is it legal , If so, you can continue to add dfs(s[2:])
ac code
class Solution:
def numDecodings(self, s: str) -> int:
# dfs + Memorize
# The top-down
@cache
def dfs(s):
if not s:
return 1
if s[0] == '0':
return 0
if len(s) == 1:
return 1
res = 0
res += dfs(s[1:])
if int(s[:2]) <= 26:
res += dfs(s[2:])
return res
return dfs(s)
summary
dfs + Memorize Indiscriminate killing
边栏推荐
- As a developer, you need to know about the codeless development platform IVX
- Go learning (IV. interface oriented)
- cout 不明确问题
- Houdini graphic notes: VAT (3.0) import ue4/5 setup wizard [official document translation]
- Spark集群安装
- ASP. Net cross page submission (button control page redirection)
- 一文2500字手把手教你使用jmeter进行分布式压力测试【保姆级教程】
- After inventing anti-virus software, he chose to be a top-notch gangster
- 联通入库|需要各地联通公司销售其产品的都需要先入总库
- ASP利用Panel实现简易注册页面
猜你喜欢

Divide the bonus pool of 10million + million yuan, and empower developers in the 2022 shengteng AI innovation competition

Small library project summary

In the shop project, implement a menu (add, delete, modify and query)
![[cloud native] use of Nacos taskmanager task management](/img/ad/24bdd4572ef9990238913cb7cd16f8.png)
[cloud native] use of Nacos taskmanager task management

Deep learning remote sensing data set

论文浅尝 | KR-GCN: 知识感知推理的可解释推荐系统

Shangsilicon Valley real-time data warehouse project (Alibaba cloud real-time data warehouse)

每日刷题记录 (八)

ASP动态创建表格 Table

89. (cesium article) cesium aggregation diagram (custom picture)
随机推荐
The correct method for Navicat to connect to mysql8.0 (valid for personal testing)
CLI tool foundation of ros2 robot f1tenth
为什么要同时重写hashcode和equals方法之简单理解
从检查点恢复后读取不到mysql的数据有那位兄台知道原因吗
Wechat bulletin number Turing robot realizes intelligent reply
泰山OFFICE技术讲座:一行中所有元素高度相同
Cout ambiguous problem
MooseFS基本概念总结
Detailed explanation of MySQL and mvcc and the difference between RC and RR for snapshot reading
[multithreading] how to implement timer by yourself
【多线程】 如何自己实现定时器
论文浅尝 | KR-GCN: 知识感知推理的可解释推荐系统
研发测试时间比,BUG数据分析
交友平台小程序制作开发代码分享
A. Marathon
Matplotlib histogram
How to prepare samples for application of color coated steel sealing plates to BS 476-3?
一文2500字手把手教你使用jmeter进行分布式压力测试【保姆级教程】
qt5.14.2连接ubuntu20.04的mysql数据库出错
ASP.NET 跨页面提交(Button控件页面重定向)