Solution in C#


  • 0
    S
        public int Reverse(int x) {
            int count = 0;
            double y=0;
            int mod=0;
            bool negative = x>0 ? false : true;
            if(negative)
            {
                x = -x;
            }
            while(x>0)
            {
                mod = x%10;
                y = mod + y*10;
                x = x/10;
            }
            if(y>((Math.Pow(2,32)/2)-1))
            {
                return 0;    
            }
            if(negative)
            {
                y=-y;
            }
            return (int)y;
        }
    }

Log in to reply
 

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