码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode] 9 - Palindrome Number

时间:2015-08-28 12:52:10      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

Determine whether an integer is a palindrome. Do this without extra space.

 

class Solution {
  public:
    bool isPalindrome(int x) {
    if (x < 0) {
      return false;
    }
    if(x < 10) {
      return true;
    }
    int base0 = 1;
    int base1 = 1;
    int x1 = x;
    while (x1 >= 10) {
      x1 /= 10;
      base1 *= 10;
    }
    while (base1 > base0) {
      int low = (x / base0) % 10;
      int high = (x / base1) % 10;
      if (low != high) {
        return false;
      }
      base0 *= 10;
      base1 /= 10;
    }
    return true;
  }
};

 

[LeetCode] 9 - Palindrome Number

标签:

原文地址:http://www.cnblogs.com/shoemaker/p/4765903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!