1. x/rec >= 10.
2. find start and end of a number.
1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 if (x < 0) return false; 5 int rec = 1; 6 while (x/rec >= 10) rec *= 10; 7 while (x > 0) { 8 int l = x/rec, r = x%10; 9 if (l != r) return false; 10 x = x%rec/10; 11 rec /= 100; 12 } 13 return true; 14 } 15 };
时间: 2024-10-08 23:37:09