number of palindromes

Enter a number to determine whether it is a palindrome

 

answer:

Because if it's negative then it's definitely not

After that, compare and remove the first and last digit to solve

 

answer:

 1 class Solution {
 2 public:
 3     bool isPalindrome(int x) {
 4        if(x<0)
 5            return false;
 6         int bit = 1;
 7         while(x/(int)pow(10,bit)!=0)
 8             bit++;
 9         while(bit>1){
10             if((x%10)!=(x/(int)pow(10,bit-1)))
11                 return false;
12             x = x%(int)pow(10,bit-1)/10;
13             bit -=2;
14         }
15         return true;
16     }
17 };

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325855174&siteId=291194637
Recommended