Palindrome Number
You get an integer x.
Return true if x is a palindrome number, and false if it is not. A palindrome number has digits that read the same from left to right and from right to left.
A negative number is never a palindrome, because the - sign is only on the left side.
Hint
The easy way is to turn x into a string and compare it with its reverse. As a challenge, try it without a string: build the reverse of the number with % 10 and integer division by 10, then compare. You only need to reverse the second half of the digits.
Examples
Example 1
- Input:
- 5225
- Output:
- true
Read from the right, 5225 is still 5225.
Example 2
- Input:
- -404
- Output:
- false
From the right it reads 404-, which is not the same. A negative number is never a palindrome.
Example 3
- Input:
- 370
- Output:
- false
From the right it reads 073. The number starts with 3 but ends with 0.
Constraints
-2^31 <= x <= 2^31 - 1
Run checks your code against the 3 examples. Submit checks it against all 243 tests and needs a free account. You can also try ideas in the free JavaScript or Python compiler.