leetcode 9回文数

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

用x/help而不用乘法(help

x=(X%help)/10去掉首尾各一位。


你可能感兴趣的:(leetcode 9回文数)