We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a716608 commit 1f0bfe3Copy full SHA for 1f0bfe3
problems/self_dividing_numbers/solution.rs
@@ -0,0 +1,26 @@
1
+impl Solution {
2
+ pub fn self_dividing_numbers(left: i32, right: i32) -> Vec<i32> {
3
+ return (left..(right + 1))
4
+ .filter(|x| is_self_dividing(*x))
5
+ .collect();
6
+ }
7
+}
8
+
9
+fn is_self_dividing(num: i32) -> bool {
10
+ let digits = get_num_digits(num);
11
+ if digits.contains(&0) {
12
+ return false;
13
14
15
+ return digits.into_iter().all(|x| num % x == 0);
16
17
18
+fn get_num_digits(mut num: i32) -> Vec<i32> {
19
+ let mut v = Vec::new();
20
+ while num != 0 {
21
+ v.push(num % 10);
22
+ num /= 10;
23
24
25
+ v
26
0 commit comments