So, I've written a 2 line solution (can be 1 line but I think this way is faster)
and it's giving right answer, but it's not getting accepted, here's the code:
def reverse(x) a = x.to_s.reverse a[-1] == '-' ? -a.to_i : a.to_i end
Why is it expecting 0??
click to show spoilers.
and you will see:
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
reversed_int > (2^31)-1 or
reversed_int < -2^31, you should return 0.