1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00
LeetCode/rs/sequential-digits.rs
Matej Focko 45fb950e25
rs: add «1291. Sequential Digits»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-02-02 20:12:25 +01:00

23 lines
490 B
Rust

impl Solution {
pub fn sequential_digits(low: i32, high: i32) -> Vec<i32> {
let mut nums = vec![];
for d in 1..=9 {
let mut num = d;
let mut next_d = d + 1;
while num <= high && next_d <= 9 {
num = 10 * num + next_d;
if low <= num && num <= high {
nums.push(num);
}
next_d += 1;
}
}
nums.sort();
nums
}
}