Problem Statement
A jumpy number is a positive integer, all of whose adjacent digits differ by at
least 2. For example,
NOT JUMPY: 28459, 28549, 1091919, 97753, 111111
JUMPY: 290464, 13131313, 97539753, 5
Create a class JumpyNum that contains a method howMany that is given low and
high and returns the number of jumpy numbers that are between low and high,
inclusive.
Definition
- Class:
- JumpyNum
- Method:
- howMany
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int howMany(int low, int high)
- (be sure your method is public)
Constraints
- low is between 1 and 2,000,000,000, inclusive.
- high is between low and 2,000,000,000, inclusive.
Examples
1
10
Returns: 9
All the single digit numbers are jumpy, but 10 isn't since 1 and 0 differ by only 1.9
23
Returns: 9
The jumpy ones are 9,13,14,15,16,17,18,19,202000000000
2000000000
Returns: 0
8000
20934
Returns: 3766