# More test cases needed

• I have the following code w/o taking care of the overflow, but it's got AC.

``````int reverse(int x) {
int sign=x>0?1:-1;
x=x*sign;
int rev=0;
while(x!=0) {
rev=10*rev+x%10;
x/=10;
}
return rev*sign;
}``````

• Me too. I do not know how to handle the overflow case

``````int reverse(int x) {
int result = x % 10;
while((x = x/10)){
result = result * 10 + x % 10;
}
return result;
}``````

• This post is deleted!

• Me too. This is my code.

``````public boolean isPalindrome(int x) {
if(x<0)
return false;
String pal = Integer.toString(x);
for(int i =0;i<=(pal.length()-1)/2;i++){
if(pal.charAt(i)!=pal.charAt(pal.length()-i-1)){
return false;
}
}
return true;
}``````

• I think you upload wrong code...

• Even this overflow unhandled code got accepted. There is no overflow check in the test cases used.

``````public class Solution{
public int reverse(int x) {
boolean flag = false;
if (x < 0) {
x = 0 - x;
flag = true;
}
int res = 0;
int p = x;

while (p > 0) {
int mod = p % 10;
p = p / 10;
res = res * 10 + mod;
}
if (flag) {
res = 0 - res;
}
return res;
}
}
``````

• Thanks for pointing this out. I have modified the problem statement to require returning 0 for overflow cases. I have also added additional test cases to test overflow behavior.