Space optimization problem for palindrome check of a number
I was recently solving the basic palindrome number check question on leetcode and wasn't able to find an optimal solution for space complexity. It wasn't space optimized. Can anybody analyse this code and give a space optimized code.
class Solution {
public:
bool isPalindrome(int x) {
if(x<0){
return false;
}
else {
int copy = x;
long new_num = 0;
while(x!=0){
new_num = (new_num)*10 + x%10;
x=x/10;
}
if (new_num == copy){
return true;
}
else{
return false;
}
}
}
};