Code works correctly when using 'Test with custm input' option but gives runtime error on Test and Submit options


#1

int Solution::reverse(int A) {
string s=to_string(A);
string r;
if(A>INT_MAX || A<INT_MIN)
return 0;
if(s.size()==1)
return A;
int n=s.size();
if(s[0]==’-’)
{
r[0]=’-’;
for(int i=1;i<n;i++)
{
r[i]=s[n-i];
}
//return stoi®;
}
else
{
for(int i=0;i<n;i++)
{
r[i]=s[n-i-1];
}
}
return stoi®;

}