int reverse(int a) {
int b = 0;
while (a>0) {
b *= 10;
b += a%10;
a /= 10;
}
return b;
}
10
Anonymous
Jul 1, 2015
To Robert: Remember integer division will truncate the value, so 93/10 = 9, not 9.3.
1
Anonymous
Jul 31, 2016
function reverseNum(num) {
let result = 0,
isNeg = num 0) {
result = result * 10 + num % 10;
num = Math.floor(num / 10);
}
return isNeg ? -1 * result : result;
}
Anonymous
Jul 31, 2016
The above formatted incorrectly.
function reverseNum(num) {
let result = 0,
isNeg = num 0) {
result = result * 10 + num % 10;
num = Math.floor(num / 10);
}
return isNeg ? -1 * result : result;
}
Anonymous
Jun 12, 2015
I am not sure this solution would work because if a was 93, your program would produce the answer 39.3, but I am not really a software guy so idk. my logic is that
a=93
93%10 = 3
b=3
a=9.3
*next iteration*
b=30
9.3%10 = 9.3
b = 39.3
is this correct? just as a disclaimer, I am not trying be an jerk, I am just practicing interview questions lol