#1291
Medium Algorithms Sequential digits
Enumeration
65.3% acceptance
Feb 25, 2026
2916
178
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.
Solution
Rust
Time O(n³)
Space O(n)
impl Solution {
pub fn sequential_digits(low: i32, high: i32) -> Vec<i32> {
let mut result = vec![];
// Generate all sequential digit numbers in order of length
for len in 2..=9usize {
for start in 1..=(10 - len) {
let mut num = 0i32;
for d in start..(start + len) {
num = num * 10 + d as i32;
}
if num >= low && num <= high {
result.push(num);
}
}
}
result
}
}