当前位置:网站首页>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
边栏推荐
- R language plot visualization: plot to visualize the normalized histograms of multiple data sets, set different histograms to use different bin sizes, and add edge axis whisker graph rugs at the botto
- State management uses session to restrict page access. Only login can verify sessionlogin Aspx can access session aspx
- Introduction to gaofen-3 satellite (GF-3)
- Go standard library context package: data, cancellation signal, deadline and other related operations between a single request and multiple goroutines and the request domain
- Add the applet "lazycodeloading": "requiredcomponents" in taro,
- 彩涂钢板密封板申请BS 476-3如何备样?
- Cout ambiguous problem
- The database of the server cannot be connected [the service has been started, the firewall has been closed, the port has been opened, and the netlent port is not connected]
- Automatic reply of wechat bulletin number intelligent reply with Turing robot
- Hardware development notes (VIII): basic process of hardware development, making a USB to RS232 module (VII): creating a basic dip component (crystal oscillator) package and associating the principle
猜你喜欢

MySQL backup and restore

从第三次技术革命看企业应用三大开发趋势

After inventing anti-virus software, he chose to be a top-notch gangster

5-minute quick start pytest testing framework

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

免费将pdf转换成word的软件分享,这几个软件一定要知道!

一文2500字手把手教你使用jmeter进行分布式压力测试【保姆级教程】

ASP using panel to realize simple registration page

IFLYTEK AI learning machine summer new product launch AI + education depth combination to create a new height of products

Data mining review
随机推荐
How to use filters in jfinal to monitor Druid for SQL execution?
As for the domestic Kirin system running QT, it can be run on the command line but cannot be run by double clicking (no response)
MySQL,MVCC详解,快照读在RC、RR下的区别
Detailed explanation of MySQL and mvcc and the difference between RC and RR for snapshot reading
Motianlun "high availability architecture" dry goods document sharing (including 124 Oracle, MySQL and PG materials)
ASP动态创建表格 Table
架构实战营毕业总结
R language plot visualization: plot visualization box graph and several box plots of multiple classification variables
Graduation summary of construction practice camp
Simple understanding of why to rewrite hashcode and equals methods at the same time
5分钟快速上手 pytest 测试框架
Structure the fifth operation of the actual camp module
JD alliance API - universal chain transfer interface - Jingpin library interface - Interface Customization
ASP. Net cross page submission (button control page redirection)
新手必须知道的 Kubernetes 架构
DevCloud加持下的青软,让教育“智”上云端
铝板AS/NZS 1530.1 不燃性材料的阻燃测试
Does rapid software delivery really need to be at the cost of security?
交友平台小程序制作开发代码分享
Mysql入库不了表情符号怎么办