当前位置:网站首页>Sword finger offer 46. translate numbers into strings
Sword finger offer 46. translate numbers into strings
2022-07-23 14:32:00 【ATTACH_ Fine】
subject
Given a number , We translate it as a string according to the following rules :0 Translate into “a” ,1 Translate into “b”,……,11 Translate into “l”,……,25 Translate into “z”. A number may have more than one translation . Please program a function , Used to calculate how many different translation methods a number has .
Example :
Ideas

Code
class Solution {
public int translateNum(int num) {
// Set up a dynamic programming list dp[i] Representative to x_i Number of translation schemes for ending numbers .
String str = String.valueOf(num);
int len = str.length();
int[] dp = new int[len+1];
dp[0] = 1;
dp[1] = 1;
for(int i = 2; i <= len; i++){
String temp = str.substring(i-2,i);
if(temp.compareTo("10") >= 0 && temp.compareTo("25") <= 0){
dp[i] = dp[i-1] + dp [i-2];
}else
dp[i] = dp[i-1];
}
return dp[len];
}
}
边栏推荐
- [review of analog electricity - diode]
- Swift hex string to uicolor
- 将我理解的web3.0讲给你听
- JS to implement encode64 encryption
- Spotlight light box JS plug-in full screen enlarged picture
- STM32输出正弦波+cubeMX配置+HAL库
- 关于flex布局justify-content:space-around最后一个不对齐的解决方法和为什么这样子解决是讨论
- Tell you Web3.0 I understand
- 几种点云(网格)孔洞填充方法(1)
- C语言实现课堂随机点名系统
猜你喜欢

回文相关题目

右键新建txt,新建文本文件不见了,通过添加注册表就可以解决,找来找去办法解决不了的终极办法
![[download attached] several scripts commonly used in penetration testing that are worth collecting](/img/01/3b74c5ab4168059827230578753be5.png)
[download attached] several scripts commonly used in penetration testing that are worth collecting

Aruba学习笔记05-配置架构- WLAN配置架构
![[review of analog electricity - diode]](/img/dc/7b3c3187000be24053f0e69733444d.jpg)
[review of analog electricity - diode]

OKRK3399開發板預留I2C4掛載EEPROM

uni-app知识点和项目上遇到的问题和解决办法的记录

【FLink】FLink Hash collision on user-specified ID “opt“. Most likely cause is a non-unique ID

338. 比特位计数

ValidationError: Invalid options object. Dev Server has been initialized using an options object th
随机推荐
antd form表单——重置方法不生效——基础积累——prop的重要性
Optimize Huawei ECs to use key login
js日历样式饼图统计插件
Canvas from getting started to persuading friends to give up (graphic version)
The shell needs to know the commands when running
Chapitre 2 requête de base et tri
链下数据互操作
Design instantiation and connection
Day 5 experiment
10 years of software testing engineer experience, very confused
c语言实现strcmp、strstr、strcat、strcpy
FFmpeg 1 - 概览/安装
Interface
Swift hex string to uicolor
Reinforcement learning -- understanding point of strategy gradient
C语言实现课堂随机点名系统
shell跑的時候需要的需要了解命令
Fastadmin changes the pop-up size of the default table button
uni-app知识点和项目上遇到的问题和解决办法的记录
Chapter 2 basic query and sorting