Reverse digits of an integer.
EXAMPLE1:X = 123, return 321
example2:x = -123, return-321
Note:
The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.
Positioning: Simple Questions
Reverses the output of the input, noting that the negative sign remains at the top, and the inverted value exceeds the Int_32bit range output 0.
Simple to pass as the number of the separation symbol after the reversal with StringBuffer, and then converted to int, at this time try to grab numberformatexception error, if there is a direct 0.
Java implementations:
1 Public classSolution {2 Public intReverseintx) {3 Booleanisnev=false;4 if(x<0){5x=-x;6isnev=true;7 }8StringBuffer stringbuffer=NewStringBuffer (string.valueof (x));9Stringbuffer=stringbuffer.reverse ();Ten inty; One Try{ Ay=Integer.parseint (stringbuffer.tostring ()); -}Catch(NumberFormatException e) { -Y=0; the } - if(Isnev) { -y=-y; - } + returny; - } +}
Leetcode 007 Reverse Integer-java