bool isPalindrome(int number, int numDigits) { int firstDigit, lastDigit, temp; if (numDigits <= 1) return true;//anchor锚例 temp = pow(10, numDigits - 1); firstDigit = number/temp;//获取数字的第一位 lastDigit = number%10;//获取数字的最后一位 if (firstDigit != lastDigit) return false; number = number%temp/10;//去除数字的第一位和最后一位剩下的数字 numDigits -= 2; isPalindrome(number, numDigits);//递归 }