Topic describes

Given an integer x, return true if x is a palindrome integer; Otherwise, return false. Palindromes are integers that read in positive (left to right) and backward (right to left) order. For example, 121 is palindrome and 123 is not.

The sample

Example 1: Input: x = 121 Output: true

Example 2: Input: x = -121 Output: false Description: The value is -121 read from left to right. Read from right to left, 121-. So it’s not a palindrome number.

Example 3: Input: x = 10 Output: false Description: Read from right to left, the value is 01. So it’s not a palindrome number.

Source: LeetCode link: leetcode-cn.com/problems/pa…

implementation

bool isPalindrome(int x)
{
    int nums[32] = {0};
    int i = 0;
    int begin = 0;
    int end = 0;
    if (x >= 0 && x < 10) {
        return true;
    }
    if (x < 0) {
        return false;
    }

    while (x) {
        nums[i++] = x % 10;
        x /= 10;
    }
    end = --i;
    while (begin < end) {
        if (nums[begin++] == nums[end--]) {
            continue;
        }
        return false;
    }
    return true;
}
Copy the code