An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
Return a sorted list of all the integers in the range [low, high]
inclusive that have sequential digits.
Input: low = 100, high = 300 Output: [123,234]
Input: low = 1000, high = 13000 Output: [1234,2345,3456,4567,5678,6789,12345]
10 <= low <= high <= 10^9
# @param {Integer} low
# @param {Integer} high
# @return {Integer[]}
def sequential_digits(low, high)
ret = []
(1..8).each do |x|
while x <= high && x % 10 != 0
ret.push(x) if x >= low
x = x * 10 + x % 10 + 1
end
end
ret.sort
end
impl Solution {
pub fn sequential_digits(low: i32, high: i32) -> Vec<i32> {
let mut ret = vec![];
for i in 1..9 {
let mut x = i;
while x <= high && x % 10 != 0 {
if x >= low {
ret.push(x);
}
x = x * 10 + x % 10 + 1;
}
}
ret.sort_unstable();
ret
}
}