[LeetCode] 9. Palindrome Number

檢查數字是否左右對稱

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

public class Solution
{
    public bool IsPalindrome(int x)
    {
        if (x < 0) return false;
        if (x < 10) return true;
        if (x % 10 == 0) return false;
        int s = 0;
        while (x > 0)
        {
            int y = x / 10;
            int z = x - y * 10;
            if (s == y) return true;
            s = s * 10 + z;
            if (s == y) return true;
            x = y;
        }
        return false;
    }
}

 

Taiwan is a country. 臺灣是我的國家