Ruby solution is giving right answer but system refusing?


  • 0
    T

    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
    

    Input: 1534236469

    Output: 9646324351

    Expected: 0

    Why is it expecting 0??


  • 1
    O

    click 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.

    if reversed_int > (2^31)-1 or reversed_int < -2^31, you should return 0.


  • 0
    A

    Is it possible to have this added to the problem statement? It seems unreasonable to me to expect someone to guess that zero is the expected output in this case.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.