13. Reverse Integer
01 Jul 2020 | Daily Algorithms
class Solution {
public:
int reverse(int x) {
long int result = 0;
while(x)
{
result = result*10 + x%10;
x/=10;
}
if(result>INT_MAX || result<INT_MIN)
{
return 0;
}
return result;
}
};
class Solution {
public:
int reverse(int x) {
long int result = 0;
while(x)
{
result = result*10 + x%10;
x/=10;
}
if(result>INT_MAX || result<INT_MIN)
{
return 0;
}
return result;
}
};
Comments