Please Help me find what is wrong with this code. Failed for a test case


#1

int Solution::isPalindrome(int A) {
string str1=to_string(A);
string str;
for(int i=0;i<str1.size();i++){
str[i]=str1[str1.size()-1-i];
}
int rev=stoi(str);
if(A==rev) return 1;
else return 0;
}


#2

by converting to a string you are using additional memory.
And you are not eliminating negative numbers.