Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- private:
- int size(int a)
- {
- int c = 0;
- while (a)
- {
- ++c;
- a /= 10;
- }
- return c;
- }
- public:
- bool isPalindrome(int x) {
- if (x < 0)
- return 0;
- int sz = size(x), tn = 1;
- for (int i = 0; i < sz-1; ++i)
- tn *= 10;
- for (int i = 0; i < sz / 2; ++i)
- {
- if (x % 10 != (x / tn) % 10)
- return 0;
- tn /= 100;
- x /= 10;
- }
- return 1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment