【leetcode】9.回文数

bool isPalindrome(int x) {

    int i,j;
    if(x < 0)return false;
    if(x == 0)return true;

    int temp[10];
    for(i = 0;i<=9&&x>=1;i++){
        temp[i] = x%10;
        x = (int)x/10;
    }
    for(j = 0;j < i;j++){
        if(temp[j]!=temp[i-j-1])
            return false;
    }
    return true;
}

运行错了一次是没注意for循环里i最后加了一次,还是要注意边界条件。

你可能感兴趣的:(leetcode)