Skip to content

Commit 462504e

Browse files
committed
src/bin/add-strings.rs
1 parent ba4f4e7 commit 462504e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/bin/add-strings.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ impl Solution {
1212
let mut vindex = v.len() - 1;
1313

1414
loop {
15-
let a = if i1 == 0 && i2 == 0 {
16-
break;
17-
} else if i1 == 0 && i2 > 0 {
15+
let a = if i1 == 0 && i2 > 0 {
1816
i2 -= 1;
1917
num2[i2] - b'0' + i
2018
} else if i1 > 0 && i2 == 0 {
@@ -23,7 +21,7 @@ impl Solution {
2321
} else {
2422
i2 -= 1;
2523
i1 -= 1;
26-
num1[i1] + num2[i2] -b'0' + i
24+
num1[i1] + num2[i2] - b'0' - b'0' + i
2725
};
2826

2927
if a >= 10 {
@@ -34,7 +32,16 @@ impl Solution {
3432
i = 0;
3533
}
3634

35+
if i1 == 0 && i2 == 0 {
36+
break;
37+
}
38+
39+
vindex -= 1;
40+
}
41+
42+
if i != 0 {
3743
vindex -= 1;
44+
v[vindex] = 1;
3845
}
3946

4047
v[vindex..].iter().fold(String::with_capacity((&v[vindex..]).len()), |mut x, y| {

0 commit comments

Comments
 (0)