9. Palindrome Number(C++)

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

 

Solution:

 

class Solution {
public:
  bool isPalindrome(int x) {
    if(x<0|| (x!=0 &&x%10==0)) return false;
    int y=0;
    while(x>y){
      y=y*10+x%10;
      x/=10;
    }
    return (y==x)||x==y/10;
  }
};

posted @ 2017-03-01 21:09  DevinGu  阅读(148)  评论(0编辑  收藏  举报