Reverse Integer


  • 0
    S

    public class Solution {
    public int reverse(int x) {
    int flag=0,y=0,i=1;
    if(x==0 || x>Integer.MAX_VALUE || x<Integer.MIN_VALUE){
    return 0;
    }
    if(x<0)
    {
    flag=1;
    x=-1*x;
    }
    while(x!=0)
    {

            	y=(int) (y*Math.pow(10, i)+x%10);
            	x=x/10;
            	
            }
            if (flag==1)
            {
            	y=-1*y;
            	
            }
            
            if(y==2147483647 || y== -2147483647|| y== -2147483648)
            return 0;
            else
    		return y;
    		
        }
    

    }


Log in to reply
 

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