Skip to content

Commit 128cc40

Browse files
committed
src/bin/difference-between-element-sum-and-digit-sum-of-an-array.rs
1 parent 8afb426 commit 128cc40

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![allow(dead_code, unused, unused_variables, non_snake_case)]
2+
3+
fn main() {}
4+
5+
struct Solution;
6+
7+
impl Solution {
8+
pub fn difference_of_sum(nums: Vec<i32>) -> i32 {
9+
let (mut a1, mut a2) = (0, 0);
10+
11+
for mut i in nums {
12+
a1 += i;
13+
14+
while i > 0 {
15+
a2 += i % 10;
16+
i /= 10;
17+
}
18+
}
19+
20+
(a1 - a2).abs()
21+
}
22+
}

0 commit comments

Comments
 (0)