由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教一道面试题
相关主题
Facebook电话面试总结FB Phone Interview Failed by a simple question
leetcode里的Palindrome partition问题面试题palindrome
最长回文串寻找下一个回文数
回文数的问题请教一道G家面试题
palindrome partioning II几道MS面试题
G四次电面面经求问一道面试题 cisco
大家帮忙看看我的Palindrome II 的解法面试问题求教
DP通项公式Bloomberg面试题
相关话题的讨论汇总
话题: 17话题: base话题: string话题: its话题: 然后
进入JobHunting版参与讨论
1 (共1页)
j******y
发帖数: 180
1
看到别人的一个面试题:
The number 131071 = 2^17 - 1 has two interesting properties:
(1) Its base-17 representation, (19b91)17, is palindromic (reading
the same backward as forward).
(2) Its base-2 representation, (11111111111111111)2, has a run of
at least 17 consecutive 1 bits.
What is the next number with both of these properties?
想了下解法, 从初始值开始每次左移一位加一,然后convert成17为base的数, 把每
一位存到list里去, 然后双指针判断是不是回文数。
悲催的是下一个数貌似很大, 我用unsigned long long也不行,最后给overflow了也
没找到。
然后想那么把17个1存string里去,每次append一个1进去,然后把以2为base的string
来convert成以17为base的string,再判断回文
所以会有一个function: bool isPalindromic( string& base2 )。 卡在这个string之
间的base conversion了。
请教一下大家有没有好的解法
l******s
发帖数: 3045
2
一点想法对于长字符串数字的除法与取模,可以二分法切割后为左侧字符串做除法及取
模以较快缩短整个字符串到long范围内。

reading

【在 j******y 的大作中提到】
: 看到别人的一个面试题:
: The number 131071 = 2^17 - 1 has two interesting properties:
: (1) Its base-17 representation, (19b91)17, is palindromic (reading
: the same backward as forward).
: (2) Its base-2 representation, (11111111111111111)2, has a run of
: at least 17 consecutive 1 bits.
: What is the next number with both of these properties?
: 想了下解法, 从初始值开始每次左移一位加一,然后convert成17为base的数, 把每
: 一位存到list里去, 然后双指针判断是不是回文数。
: 悲催的是下一个数貌似很大, 我用unsigned long long也不行,最后给overflow了也

q***a
发帖数: 26
3
读题。
"has a run of at least 17 consecutive 1 bits" doesn't mean all bits are 1s.

reading

【在 j******y 的大作中提到】
: 看到别人的一个面试题:
: The number 131071 = 2^17 - 1 has two interesting properties:
: (1) Its base-17 representation, (19b91)17, is palindromic (reading
: the same backward as forward).
: (2) Its base-2 representation, (11111111111111111)2, has a run of
: at least 17 consecutive 1 bits.
: What is the next number with both of these properties?
: 想了下解法, 从初始值开始每次左移一位加一,然后convert成17为base的数, 把每
: 一位存到list里去, 然后双指针判断是不是回文数。
: 悲催的是下一个数貌似很大, 我用unsigned long long也不行,最后给overflow了也

s**********x
发帖数: 120
4
我觉得可以直接对字符串乘2加1来计算呀,然后判断新的字符串是不是对称的。
绕开了溢出的问题。
1 (共1页)
进入JobHunting版参与讨论
相关主题
Bloomberg面试题palindrome partioning II
palindrome int这个recursive能再java上实现么?G四次电面面经
请问关于字符串的面试题一般用c-style还是string class?大家帮忙看看我的Palindrome II 的解法
面试题:根据输入字符串,返回正则表达式DP通项公式
Facebook电话面试总结FB Phone Interview Failed by a simple question
leetcode里的Palindrome partition问题面试题palindrome
最长回文串寻找下一个回文数
回文数的问题请教一道G家面试题
相关话题的讨论汇总
话题: 17话题: base话题: string话题: its话题: 然后