首页 > 其他 > 详细

[LeetCode] 9 - Palindrome Number

时间:2015-08-28 12:52:05      阅读:87      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!