Reverse digits of an integer. Example1: x = , return
Example2: x = -, return -
class Solution {
public:
int reverse(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(x == ) return x;
int flag = ; if(x < )
{
x*= -;
flag = -;
}
vector<int> result;
while(x)
{
int temp = x %;
result.push_back(temp);
x/=;
}
int num = ;
for(int i = ; i< result.size(); i++)
{
num +=result[i];
num*=;
} return flag*num/ ;
}
};