LeetCode: Palindrome Number

一点小失误,基本一次过吧

 1 class Solution {
 2 public:
 3     bool isPalindrome(int x) {
 4         // Start typing your C/C++ solution below
 5         // DO NOT write int main() function
 6         int mul = 1;
 7         if (x < 0) return false;
 8         while (x/10 >= mul) mul *= 10;
 9         while (x) {
10             int left = x / mul;
11             int right = x % 10;
12             if (left != right) return false;
13             x -= left*mul;
14             x = (x - right) / 10;
15             mul /= 100;
16         }
17         return true;
18     }
19 };

 C#

 1 public class Solution {
 2     public bool IsPalindrome(int x) {
 3         int mul = 1;
 4         if (x < 0) return false;
 5         while (x / 10 >= mul) mul *= 10;
 6         while (x > 0) {
 7             int left = x / mul;
 8             int right = x % 10;
 9             if (left != right) return false;
10             x -= left * mul;
11             x = (x - right) /10;
12             mul /= 100;
13         }
14         return true;
15     }
16 }
View Code
原文地址:https://www.cnblogs.com/yingzhongwen/p/3029854.html