Simple solution in Java


  • 0
    G

    Firstly, long "reversed" in case of integer overflow.
    Secondly, Iterate "reversed = reversed*10 + x/10" and "x/=10" until "x==0".
    Finally, check if result overflows integer maximum or minimum to determine whether return 0 or not. return the int-casted "reversed".


Log in to reply
 

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