LeetCode-9.Palindrome Number

https://leetcode.com/problems/palindrome-number/

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

Do this without extra space的意思:You could use variable in (without extra space) as variable come under order(1) domain.

 public bool IsPalindrome(int x)
        {
            if (x < 0)
                return false;
            int y=0,tmp = x;
            while (x != 0)
            {
                y = y * 10 + x % 10;
                x /= 10;
            }
            return y == tmp;
        }


你可能感兴趣的:(LeetCode)