当前位置:网站首页>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
边栏推荐
- 架构实战营毕业总结
- jfinal中如何使用过滤器监控Druid监听SQL执行?
- Reflections on remote sensing image interpretation
- Spark集群安装
- Mysql入库不了表情符号怎么办
- 从第三次技术革命看企业应用三大开发趋势
- 分析安装包LNMP中的apache.sh脚本
- Shangsilicon Valley real-time data warehouse project (Alibaba cloud real-time data warehouse)
- Wechat bulletin number Turing robot realizes intelligent reply
- Huawei cloud AOM version 2.0 release
猜你喜欢

Golang operation etcd

leetcode:91. 解码方法【dfs + 记忆化】

Three development trends of enterprise application viewed from the third technological revolution

尚硅谷实时数据仓库项目(阿里云实时数仓)

Reading notes on how to connect the network - Web server request and response (V)

美国隧道法ASTM E84 表面阻燃测试

科大讯飞 AI 学习机暑期新品发布会 AI + 教育深度结合再创产品新高度

ASP动态创建表格 Table

Deep learning remote sensing data set

Motianlun "high availability architecture" dry goods document sharing (including 124 Oracle, MySQL and PG materials)
随机推荐
Simple understanding of why to rewrite hashcode and equals methods at the same time
ASP.NET 跨页面提交(Button控件页面重定向)
CLI tool foundation of ros2 robot f1tenth
期末实训 简单通讯录 c语言
新手必须知道的 Kubernetes 架构
American tunneling ASTM E84 surface flame retardant test
Datakit acts as an API server for local data acquisition
Add the applet "lazycodeloading": "requiredcomponents" in taro,
Can cdc2.2.1 listen to multiple PgSQL libraries at the same time?
The logic behind the three whys encountered in technical communication
客户端可以连接远程mysql
DevCloud加持下的青软,让教育“智”上云端
Reading notes on how to connect the network - Web server request and response (V)
泰山OFFICE技术讲座:一行中所有元素高度相同
Introduction, deployment and application of moosefs
Final training simple address book c language
每日刷题记录 (八)
Writing a makefile for a golang project
硅树脂油漆申请美国标准UL 790 Class A 合适吗?
jfinal中如何使用过滤器监控Druid监听SQL执行?