【leetcode】 9. palindrome number
阿新 • • 發佈:2018-04-18
ble number cli ack ont art ews styles doc
@requires_authorization
@author johnsondu
@create_time 2015.7.13 9:48
@url [palindrome-number](https://leetcode.com/problems/palindrome-number/)
/************************
* 分離出最左邊和最右邊的數
* 然後依次對照就可以
***********************/
class Solution {
public:
bool isPalindrome (int x) {
if(x < 0) return false;
if(x < 10) return true;
int base = 1;
while(x / base >=10) base *= 10;
while(x)
{
int ld = x / base;
int rd = x % 10;
if(ld != rd) return false;
x -= ld * base;
x /= 10 ;
base /= 100;
}
return true;
}
};
【leetcode】 9. palindrome number