Skip to content

Commit 1c506bb

Browse files
authored
Create solution.rs
1 parent bbc01b5 commit 1c506bb

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

415.add_string/solution.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
impl Solution
2+
{
3+
pub fn add_strings(mut num1: String,mut num2: String) -> String
4+
{
5+
let mut temp = String::new();
6+
let mut v:u8 = 0;
7+
loop
8+
{
9+
let v1 = num1.pop();
10+
let v2 = num2.pop();
11+
if v1 == None && v2 == None && v ==0
12+
{
13+
break;
14+
}
15+
if let Some(v1) = v1
16+
{
17+
v += v1 as u8 - 48;
18+
}
19+
if let Some(v2) = v2
20+
{
21+
v+= v2 as u8 - 48;
22+
}
23+
let v3:u8 = v%10;
24+
temp.push_str(&(v3.to_string()));
25+
v /= 10;
26+
}
27+
let mut rst = String::new();
28+
loop
29+
{
30+
if let Some(ch) = temp.pop()
31+
{
32+
rst.push(ch);
33+
}
34+
else
35+
{
36+
break;
37+
}
38+
}
39+
return rst;
40+
}
41+
}

0 commit comments

Comments
 (0)