Palindrome Number
Given an integer x, determine whether it is a palindrome. An integer is a palindrome if it reads the same forwards and backwards when interpreted as a…
Given an integer `x`, determine whether it is a palindrome. An integer is a palindrome if it reads the same forwards and backwards when interpreted as a sequence of digits. Solve this without converting the integer to a string.
- `-2^31 <= x <= 2^31 - 1` - The interactive visualizer accepts `-10^9 <= x <= 10^9`; larger valid signed 32-bit inputs are supported by Run and Submit without a trace. - Negative numbers are never palindromes because the leading minus sign has no matching character on the right. - Single-digit non-negative integers (0 through 9) are always palindromes.
Example 1: input x = 1331; output true. Reading 1331 from left to right gives 1, 3, 3, 1. Reading it right to left gives the same sequence, so it is a palindrome.
Example 2: input x = 4587; output false. The number reversed is 7854, which differs from 4587, so it is not a palindrome.
Example 3: input x = -252; output false. Negative integers are never palindromes because the minus sign exists on the left side only, making the reversed form structurally different.
Category: Math. Topic: math. Difficulty: Easy. Patterns: math.