Skip to content

Commit 807f27d

Browse files
committed
compute_decimal_representation.rs
1 parent ec8d69b commit 807f27d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
impl Solution {
2+
pub fn decimal_representation(mut n: i32) -> Vec<i32> {
3+
let mut v = Vec::new();
4+
let mut p = 1;
5+
while n > 0 {
6+
let d = n % 10;
7+
if d != 0 {
8+
v.push(d * p);
9+
}
10+
p *= 10;
11+
n /= 10;
12+
}
13+
v.into_iter().rev().collect()
14+
}
15+
}

0 commit comments

Comments
 (0)