当前位置:网站首页>leetcode 91. Decode Ways 解码方法(中等)
leetcode 91. Decode Ways 解码方法(中等)
2022-06-23 03:47:00 【InfoQ】
一、题目大意
- 1 <= s.length <= 100
- s 只包含数字,并且可能包含前导零。
二、解题思路
三、解题方法
3.1 Python实现
class Solution(object):
def numDecodings(self, s):
"""
:type s: str
:rtype: int
"""
dp = [0] * (len(s) + 1)
dp[0] = 1
for i in range(1, len(dp)):
if s[i-1] != '0':
dp[i] = dp[i-1]
if i != 1 and '09' < s[i-2:i] < '27':
dp[i] += dp[i-2]
return dp[-1]
四、总结小记
- 2022/6/22 试着用Python解决leetcode
边栏推荐
- [Zeng shuge's laser slam notes] gmapping filter based slam
- [tcapulusdb knowledge base] [list table] example code for deleting the data at the specified location in the list
- mysql能不能在linux中使用
- JS array de duplication, removing the same value
- Bug STM32 advanced timer (haha, to tell you the truth, the hardware timer can't reflect its strength. In fact, I want to send the kernel timer. Just think about it. Take your time)
- 在线文本过滤小于指定长度工具
- Tables de recherche statiques et tables de recherche statiques
- 会话和守护进程
- 京东云分布式数据库StarDB荣获中国信通院 “稳定性实践先锋”
- [leetcode] sum of two numbers II
猜你喜欢

Two ways to improve the writing efficiency of hard disk storage data

2022年的软件开发:首席信息官应该知道的五个现实

bubble sort

怎么使用Shell脚本实现监测文件变化

会话和守护进程

在 KubeSphere 上部署 Apache Pulsar

给你的AppImage创建桌面快捷方式
![[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation](/img/eb/0d4caf0babbe14f51f4dbf1b9ae65d.png)
[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation

Code refactoring Guide

深度学习 TensorFlow入门
随机推荐
Insert sort directly
How to realize data transaction
Implementation of VGA protocol based on FPGA
Differences between MyISAM and InnoDB of MySQL storage engine
Preface
1-1 introduction to VMWare
node+express如何操作cookie
Avltree - arbre de recherche binaire équilibré
Full analysis of embedded software testing tool tpt18 update
[binary tree] 993 Cousins in Binary Tree
Pytorch---使用Pytorch的预训练模型实现四种天气分类问题
The first batch of job hunting after 00: don't misread their "different"
Create a desktop shortcut to your appimage
虫子 日期类 上 太子语言
[leetcode] flip linked list II
粒子动画背景登录页面particles.js
The tax software exits when it detects that it is a virtual machine. How to solve this problem?
浅析2022年物联网现状
mysql存储引擎之Myisam和Innodb的区别
炫酷鼠标跟随动画js插件5种