mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
rs: add «1291. Sequential Digits»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
feee06dc93
commit
45fb950e25
1 changed files with 23 additions and 0 deletions
23
rs/sequential-digits.rs
Normal file
23
rs/sequential-digits.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue