当前位置:网站首页>剑指offer46把数字翻译成字符串
剑指offer46把数字翻译成字符串
2022-07-26 19:41:00 【原来是大海】
给定一个数字,我们按照如下规则把它翻译为字符串:0 翻译成 “a” ,1 翻译成 “b”,……,11 翻译成 “l”,……,25 翻译成 “z”。一个数字可能有多个翻译。请编程实现一个函数,用来计算一个数字有多少种不同的翻译方法。
class Solution:
def translateNum(self, num: int) -> int:
s = str(num)
a = b = 1
for i in range(2, len(s) + 1):
tmp = s[i - 2:i]
c = a + b if "10" <= tmp <= "25" else a
b = a
a = c
return a
边栏推荐
- MySQL InnoDB engine (V)
- SQL优化的一些建议,希望可以帮到和我一样被SQL折磨的你
- ES6 method & Class array into real array & method of judging array
- Strengthen supervision on secret room escape and script killing, and focus on strengthening fire safety and juvenile protection
- Usage of Smoothscroll Polyfill plug-in
- Pandonia spirit voxedit creation competition
- gospel! Wechat personal official account can be renamed!
- 使用百度飞桨 EasyDL 完成垃圾分类
- 同花顺靠谱吗?我刚开始学习理财,开证券账户安全吗?
- 文件上传的方式和下载
猜你喜欢

The typing competition is over!

查询字段较多时可以添加普通查询和高级查询两种情况

有点酷,使用 .NET MAUI 探索太空

一维数组定义与使用

软件测试-开发提测内容规范(项目提测模板)
![[record of question brushing] 22. bracket generation](/img/0d/8881fcbcd0e963875dff2946b95865.png)
[record of question brushing] 22. bracket generation

Fitting the new direction of curriculum standards, ape guidance, creating a characteristic new concept content system

使用请求头认证来测试需要授权的 API 接口

C asynchronous programming read this article is enough

The sandbox cooperates with artist Alec monopoly
随机推荐
潘多尼亚精灵 VoxEdit 创作大赛
Usage of Smoothscroll Polyfill plug-in
arpspoof 安装和使用
静音台式风扇芯片-DLTAP703SD-杰力科创
一维数组定义与使用
EasyCVR设备管理列表页面,分页数据不显示的问题修复
three. JS tag and pop-up the earth
Is flush reliable? I just started to learn financial management. Is it safe to open a securities account?
Kotlin - 协程上下文 CoroutineContext
AI 技术,让复杂世界简单化 | TeaTalk·Online 应用实战系列第 2 期
Dio问题总结
任务一 报告
this指向,最简单的规则记住它
文件上传的方式和下载
打字比赛圆满结束!
SwiftUI 4 新功能之实时获取点击位置 .onTapGesture { location in} (教程含源码)
猿辅导的科技硬实力:让AI从读懂孩子作业开始
Exchange 2010 SSL证书安装文档
Strengthen supervision on secret room escape and script killing, and focus on strengthening fire safety and juvenile protection
C asynchronous programming read this article is enough