MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/easy/_0007/Solution.java:11–26  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/04/19 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public class Solution {
12 public int reverse(int x) {
13 long res = 0;
14 for (; x != 0; x /= 10)
15 res = res * 10 + x % 10;
16 return res > Integer.MAX_VALUE || res < Integer.MIN_VALUE ? 0 : (int) res;
17 }
18
19 public static void main(String[] args) {
20 Solution solution = new Solution();
21 System.out.println(solution.reverse(123));
22 System.out.println(solution.reverse(-123));
23 System.out.println(solution.reverse(100));
24 System.out.println(solution.reverse(1000000003));
25 }
26}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected