Determine whether an integer is a palindrome. Do this without extra space.
====================================================================================
题目链接:https://leetcode.com/problems/palindrome-number/
题目大意:求一个整数是否对称,如6、11、121、1221、32623等等。
思路:先用一个栈按顺序存储x中数字,再判断栈中数字是否对称即可。
附上代码:
class Solution {
public:
bool isPalindrome(int x) {
if( x < 0 )
return false ;
if ( x == 0 )
return true ;
vector <int> v ;
while ( x )
{
v.push_back ( x % 10 ) ;
x /= 10 ;
}
int n = v.size() ;
for ( int i = 0 ; i < n / 2 ; i ++ )
if ( v[i] != v[n-1-i] )
return false ;
return true ;
}
};