Determine whether an integer is a palindrome. Palindrome correct order (from left to right) and reverse (right to left) reading is the same integer.
Example 1:
Input: 121
Output: true
Example 2:
Input: -121
Output: false
explanation: read from left to right, as -121. Reading from right to left, as 121-. So it is not a palindrome number.
Example 3:
Input: 10
Output: false
interpretation: reading from right to left, to 01. So it is not a palindrome number.
Source: stay button (LeetCode)
link: https: //leetcode-cn.com/problems/palindrome-number
copyrighted by deduction from all networks. Commercial reprint please contact the authorized official, non-commercial reprint please indicate the source.
Package Leetcode; public class Solution_1 { public static Boolean IsPalindrome ( int X) { // Special case: // As described above, when x <0, x is not a palindrome. // Similarly, if the number of the last bit is 0, in order to make the number is a palindrome, // it first digit should be 0 // only meet this attribute 0 IF (the X-<0 || ( !% 10 == 0 && X X = 0 )) { return to false ; } int revertedNumber = 0 ; the while (X> revertedNumber) { revertedNumberRevertedNumber * X + 10 = 10% ; X / = 10 ; } // When the length is an odd number, we may be removed by revertedNumber / 10 in number of bits. // For example, when the input is 12321, while at the end of the cycle we get 12 is = X, revertedNumber = 123, // since in the position number is not palindromic (which is always equal to himself), so we can simply be removed. return X == == revertedNumber revertedNumber || X / 10 ; } public static void main (String [] args) { System.out.println (IsPalindrome ( 121 )); } }