
prevPalindrome
iven a positive integer x
, find the greatest number smaller than x
that is a palindrome.
A number is considered to be a palindrome if its string representation looks the same when written backwards as it does when written forwards. For example, 1991
, 7
and 808
are all palindromes.
Example:
-
For
x = 16
, the output should beprevPalindrome(x) = 11
.11
is the greatest palindrome that is smaller than16
. -
For
x = 11
, the output should beprevPalindrome(x) = 9
.
Input/Output:
-
[execution time limit] 0.5 seconds
-
[input] integer x
An integer.
1 ≤ x ≤ 109
. -
[output] integer
The greatest palindrome number that is smaller thanx
.
Post Comment