Solution in java


  • 0
    C

    【1】

    class Solution {

    public int reverse(int x)  {
    
        int tmp = Math.abs(x);
            long result = 0;
            while (tmp>0){
                int n = tmp%10;
                result = result*10 + n;
                if (result >Integer.MAX_VALUE) {
                    return 0;
                }
                tmp = tmp/10;
            }
            return (int)(x >=0?result:-result);
    }
    

    }
    【2】
    class Solution {

    public int reverse(int x) {
    
        int temp = Math.abs(x);
        String strTemp = Integer.toString(temp);
        StringBuffer strBuffer = new StringBuffer(strTemp);
        String result = strBuffer.reverse.toString();
        if(Long.parseLong(result) > Integer.MAX_VALUE) {
                 return "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.