Testcase wrong 10000021


  • 0
    H

    My code passed OJ, but some test cases should be wrong. For example, 10000021 is not palindrome, but it is true in the code below. In a word, the code cannot handle cases with zeros.

    public class Solution {
    public boolean isPalindrome(int x) {
        if(x<0) return false;
        int m=1;
        while(x/m>=10){
            m=m*10;
        }
        while(x>=10){
            if(x/m!=x%10) return false;
            x=x%m;
            x=x/10;
            m=m/100;
        }
        return true;
    }
    

    }


  • 0

    Thanks and welcome @housevenn, I have just added this test case.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.