Java solution sample


  • 0
    B

    class Solution {
    public int reverse(int x) {
    Integer res = 0;
    try {
    res = Integer.valueOf((new StringBuilder(Integer.toString(x)).reverse().toString()).replace("-",""));
    } catch (NumberFormatException e) {
    // Happens only when the reversed integer overflows.
    return 0;
    }
    return x < 0 ? res * (-1) : res;
    }
    }


Log in to reply
 

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