Reverse digits of an integer.
If the last digit are 0, what should the output being? ie, cases such as 10, 100.
Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer,
Then the reverse of 1000000003 overflows. How should handle such cases?
For the purpose of this problem, assume a your function returns 0 when the reversed integer overflows.
EXAMPLE1:X = 123, return 321
example2:x = -123, return-321
Requirements: Reverse shaping numbers, you need to take into account negative numbers and shaping the number overflow problem
10100
=>101
1000000003
=>0
-2147483648
=
2147483647
-2147483648
Public intReverseintx) {StringBuilder sb=NewStringBuilder (); intMoD, flag=0; Booleantemp =false; if(X==0 | | x==integer.min_value)return0; if(x<0) {x=Math.Abs (x); Temp=true; } System.out.println (x); while(x>0) {mod= x%10; if(Mod==0 && flag==0) {}Else{sb.append (mod+""); Flag++; } x= X/10; } Longval =long.valueof (sb.tostring ()); intres = (val>integer.max_value)? 0: (int) Val; if(temp) Res= -Res; returnRes; }
[Leetcode]-algorithms-reverse Integer