Solution in Java


  • 0
    A

    class Solution {
    public int reverse(int x) {
    int temp = Math.abs(x);
    String str = Integer.toString(temp);
    StringBuffer sb = new StringBuffer(str);
    String result = sb.reverse().toString();
    if(Long.parseLong(result) > Integer.MAX_VALUE){
    result = "0";
    }
    return x > 0? Integer.parseInt(result) : -Integer.parseInt(result);
    }
    }


Log in to reply
 

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