当前位置:网站首页>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];
}
}
边栏推荐
猜你喜欢
随机推荐
Le shell a besoin de connaître les commandes
Interface
云呐-如何加强固定资产管理?怎么加强固定资产管理?
FFmpeg 2 - ffplay、ffprobe、ffmpeg 命令使用
第2章 基礎查詢與排序
STM32 output sine wave +cubemx configuration +hal Library
優化華為雲服務器采用Key登陸
pageHepler丢失原sql order by条件的坑
js软件卸载提示表情跟随鼠标变化js特效
炫酷代码雨动态背景注册页面
C语言实现课堂随机点名系统
spotlight灯箱js插件全屏放大图片
【模电复习——二极管】
The shell needs to know the commands when running
手工测试如何转向自动化测试?字节5年自动化经验浅谈一下...
Design instantiation and connection
Pycharm读取Excel文件时报错:raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+ ; not supported )
Drag and drop----
Vk36n5d anti power interference / mobile phone interference 5-key 5-channel touch detection chip anti freeze function ponding in the touch area can still be operated
Cool code rain dynamic background registration page





![寻找峰值[抽象二分练习]](/img/99/122e79784f0f07120680d2cbcf89da.png)



