/* Determine whether an integer is a palindrome. Do this without extra space.
A palindrome integer is an integer x for which reverse(x) = x where reverse(x) is x with its digit reversed.
Negative numbers are not palindromic.
*/
A palindrome integer is an integer x for which reverse(x) = x where reverse(x) is x with its digit reversed.
Negative numbers are not palindromic.
*/
#include <iostream>
using namespace std;
bool isPalindrome(int N){
if(N < 0){
return false;
}
int temp = N;
int reversed = 0;
while(temp > 0){
reversed = 10 * reversed + temp % 10;
temp = temp / 10;
}
return reversed == N;
}
int main(){
int N = 1001001;
if(isPalindrome(N)){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
}
0 comments:
Post a Comment