mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-17 16:51:46 +00:00
14 lines
353 B
Java
14 lines
353 B
Java
class IntegerReverse {
|
|
public int reverse(int num) {
|
|
if (num == 0)
|
|
return 0;
|
|
|
|
try {
|
|
return Integer.parseInt(new StringBuilder(Integer.toString(Math.abs(num))).reverse().toString())
|
|
* (num < 0 ? -1 : 1);
|
|
} catch (NumberFormatException err) {
|
|
return 0;
|
|
}
|
|
}
|
|
}
|