Leetcode 9 Palindrome Number C#

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

 

Solution:

 public bool IsPalindrome(int x) {
        if(x<0) return false;
        if(x == 0 || x/10 ==0) return true;
        int y = 0;
        int sentinel = x;
        while(x>0 )
        {
            y =y*10 + x%10;
            x = x/10;
           
        }
        return sentinel==y ;
    }

 

posted @ 2016-08-24 05:00  咖啡中不塌缩的方糖  阅读(286)  评论(0编辑  收藏  举报