由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问个amazon面试题。
相关主题
google phone interview,直接跪了,以前没做过,做过的应该不难一道facebook面试题
G 家电面面经请问这道题如何做?Zero-one multiple
G家面经(已被HC挂,求分析)FLG面经回馈版面和感想
Google onsite问题面试问题求教
一道面试题(integer to binary string)大家帮我看看这个程序哪里有问题啊!!
问一个facebook的电面DP 的 memorized 放在哪里?
请教一个reverse decimal number的问题请教一道, leetcode题.
除法有什么规律吗?Facebook Phone Inteview + 流程请教
相关话题的讨论汇总
话题: int话题: string话题: iset话题: remainders
进入JobHunting版参与讨论
1 (共1页)
B*******1
发帖数: 2454
1
Given Numerator and Denominator. After division you might get a recurring
decimal points float as the answer. You need to identify the recurring part?
For example 23.34563456 ...
return 3456
完全没有idea,请大牛们指教。
d********y
发帖数: 2114
2
小学的时候笔算,当出现相同的余数就开始循环了。
用hash记录小数点后面每一位的余数?
f*******t
发帖数: 7549
3
我觉得可以把余数放进set
先取余数,然后不断乘以10再取余
如果发现重复的余数,从它开始不断取商放进结果中,直到余数再次重复,所得的就是循环的数字
k****n
发帖数: 369
4
do it directly as you do by hand?
int division(int numerator, int denominator) {
HashMap remainders = new HashMap();
StringBuffer sb = new StringBuffer();
sb.append(numerator / denominator).append(".");
return helper(numerator % denominator, denominator, remainders, sb);
}
int helper(int n, int d, HashMap remainders, StringBuffer
result) {
if (n == 0) return 0; // non-recurring
if (remainders.containsKey(n)) {
return result.toString().substring(remainders.get(n).length());
}
remainders.put(n, result.toString());
int r = 10 * n % d;
return helper(r, d, remainders, result.append(10*n / d));
}

part?

【在 B*******1 的大作中提到】
: Given Numerator and Denominator. After division you might get a recurring
: decimal points float as the answer. You need to identify the recurring part?
: For example 23.34563456 ...
: return 3456
: 完全没有idea,请大牛们指教。

k****n
发帖数: 369
5
说的是记录余数,不是除的结果
S**I
发帖数: 15689
6
OK, I see

【在 k****n 的大作中提到】
: 说的是记录余数,不是除的结果
d*******d
发帖数: 2050
7
string find_circle(int x, int y){
typedef unordered_set ISET;
ISET iset;
int i = x/y;
x = x-i*y;
string res = "";
while(x>0){
x = x*10;
pair ret = iset.insert(x);
if( ret.second == false)
break;
i = x/y;
x = x - i*y;
char c = '0' + i;
res += c;
}
return res;
}
S**I
发帖数: 15689
8
I think your code needs a small modification: there could be leading 0's in
the return string and they should be removed.

【在 k****n 的大作中提到】
: do it directly as you do by hand?
: int division(int numerator, int denominator) {
: HashMap remainders = new HashMap();
: StringBuffer sb = new StringBuffer();
: sb.append(numerator / denominator).append(".");
: return helper(numerator % denominator, denominator, remainders, sb);
: }
: int helper(int n, int d, HashMap remainders, StringBuffer
: result) {
: if (n == 0) return 0; // non-recurring

k****n
发帖数: 369
9
I think I have removed them...
But I haven't checked my code, maybe you are right, thanks...

in

【在 S**I 的大作中提到】
: I think your code needs a small modification: there could be leading 0's in
: the return string and they should be removed.

1 (共1页)
进入JobHunting版参与讨论
相关主题
Facebook Phone Inteview + 流程请教一道面试题(integer to binary string)
贡献一道面试题问一个facebook的电面
问一个面试题请教一个reverse decimal number的问题
继续贴几个题目除法有什么规律吗?
google phone interview,直接跪了,以前没做过,做过的应该不难一道facebook面试题
G 家电面面经请问这道题如何做?Zero-one multiple
G家面经(已被HC挂,求分析)FLG面经回馈版面和感想
Google onsite问题面试问题求教
相关话题的讨论汇总
话题: int话题: string话题: iset话题: remainders