Java Solution


  • 0
    A


    class Solution {
    public int reverse(int x) {
    try {
    String r = x < 0 ? "-" : "";
    do {
    x = x > 0 ? x : -x;
    r += x%10;
    x /= 10;
    } while (x != 0);
    return Integer.parseInt(r);
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    return 0;
    }
    }


Log in to reply
 

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