rs: add «1291. Sequential Digits»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-02-02 20:12:25 +01:00
parent feee06dc93
commit 45fb950e25
Signed by: mfocko
GPG key ID: 7C47D46246790496

23
rs/sequential-digits.rs Normal file
View file

@ -0,0 +1,23 @@
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
}
}