41. Palindrome Numbers in a Range
Difficulty: easy · Math
Problem
Given a range of integers from `M` to `N` (both inclusive), count how many of them are palindrome numbers. A palindrome number reads the same backwards as forwards, for example `121`, `131`, `11` and `9`.
Input
- Line 1: the integer `M` (lower limit). - Line 2: the integer `N` (upper limit).
Output
Print the number of palindromes in `[M, N]`.
Example 1
Input: 10 20 Output: 1
Explanation: Only 11 lies between 10 and 20 and reads the same both ways.
Example 2
Input: 1 100 Output: 18
Explanation: 1 to 9 (nine numbers) plus 11, 22, ..., 99 (nine more) gives 18.
Constraints
- 0 <= M <= N <= 10^6
Solutions are judged against 2 sample and 10 hidden tests. Sign in to solve it · All problems