Redian新闻
>
面试题分享:把数字翻译成字符串
avatar
面试题分享:把数字翻译成字符串# JobHunting - 待字闺中
z*t
1
写了篇博客讨论下面的面试题:
Given a number, please translate it to a string, following the rules: 1 is
translated to 'a', 2 to 'b', …, 12 to 'l', …, 26 to 'z'. For example, the
number 12258 can be translated to "abbeh", "aveh", "abyh", "lbeh" and "lyh",
so there are 5 different ways to translate 12258. How to write a function/
method to count the different ways to translate a number?
博客URL:http://codercareer.blogspot.com/2014/09/no-55-translating-numbers-to-string.html
这个题目用递归分析,不难找出解题思路。但有两点细节需要注意:
1、递归的子问题有可能重复。写代码时要确保子问题不会被重复计算;
2、题目没有明确说0怎么翻译,那么诸如数字101等包含0的数字怎么翻译?这可以和面
试官讨论。这可能是面试官考查沟通能力的地方。
avatar
f*w
2
Leetcode原题,decode ways
avatar
x*B
3
为啥别人面得时候都是老题呢。。

the
",

【在 z******t 的大作中提到】
: 写了篇博客讨论下面的面试题:
: Given a number, please translate it to a string, following the rules: 1 is
: translated to 'a', 2 to 'b', …, 12 to 'l', …, 26 to 'z'. For example, the
: number 12258 can be translated to "abbeh", "aveh", "abyh", "lbeh" and "lyh",
: so there are 5 different ways to translate 12258. How to write a function/
: method to count the different ways to translate a number?
: 博客URL:http://codercareer.blogspot.com/2014/09/no-55-translating-numbers-to-string.html
: 这个题目用递归分析,不难找出解题思路。但有两点细节需要注意:
: 1、递归的子问题有可能重复。写代码时要确保子问题不会被重复计算;
: 2、题目没有明确说0怎么翻译,那么诸如数字101等包含0的数字怎么翻译?这可以和面

avatar
r*3
4
求问 如果要你把所有可能性都打印出来, 复杂度是不是就变成和递归复杂度一样了?
avatar
z*t
5
看怎么实现代码吧。关键是去除重复的子问题。如果用循环从右往左翻译,比直接用递
归应该要快一些。
我试着写了一下,放在如下URL:
http://ideone.com/A5SOYM

【在 r*****3 的大作中提到】
: 求问 如果要你把所有可能性都打印出来, 复杂度是不是就变成和递归复杂度一样了?
avatar
y*n
6
大名鼎鼎的Harry也要出山了。

the
",

【在 z******t 的大作中提到】
: 写了篇博客讨论下面的面试题:
: Given a number, please translate it to a string, following the rules: 1 is
: translated to 'a', 2 to 'b', …, 12 to 'l', …, 26 to 'z'. For example, the
: number 12258 can be translated to "abbeh", "aveh", "abyh", "lbeh" and "lyh",
: so there are 5 different ways to translate 12258. How to write a function/
: method to count the different ways to translate a number?
: 博客URL:http://codercareer.blogspot.com/2014/09/no-55-translating-numbers-to-string.html
: 这个题目用递归分析,不难找出解题思路。但有两点细节需要注意:
: 1、递归的子问题有可能重复。写代码时要确保子问题不会被重复计算;
: 2、题目没有明确说0怎么翻译,那么诸如数字101等包含0的数字怎么翻译?这可以和面

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。