[007] Reverse Integer Wrong expected answer?


  • 0
    J

    This is my code below

    class Solution {
        func reverse(x: Int) -> Int {
            if x == 0 {
                return x
            }
            var input   = x
            var ret     = 0;
            while input != 0 {
                ret     = ret*10 + input%10;
                input   = input/10;
            }
            return ret
        }
    }
    

    but is expected answer wrong ?

    Input: 1534236469

    My Code Output: 9646324351

    Expected: 0 ?? => Why Expected is 0 ?


  • 0
    E

    when ret>INT_MAX or ret<INT_MIN,

    return 0.

    You can see the words after 'click to show spoilers':

    Update (2014-11-10): Test cases had been added to test the overflow
    behavior.


  • 0
    J

    But in Swift, Type "Int" max value can store is 9223372036854775807
    1534236469 did't overflow


  • 0
    E

    Oh...so it was the author's mistake


  • 0
    C

    I have the same problem. So what's the INTMAX ?


Log in to reply
 

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