Skip to content

Commit 4556320

Browse files
committed
Create 2109-adding-spaces-to-a-string.rs
1 parent f0baa1f commit 4556320

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

2109-adding-spaces-to-a-string.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub fn add_spaces(s: String, spaces: Vec<i32>) -> String {
2+
let mut s = s;
3+
let mut z = 0;
4+
for space in spaces {
5+
let idx = space + z;
6+
s.insert(idx as usize, ' ');
7+
z += 1;
8+
}
9+
s
10+
}
11+
12+
fn main() {
13+
let s = "LeetcodeHelpsMeLearn".to_string();
14+
let spaces = vec![8,13,15];
15+
println!("{:?}", add_spaces(s, spaces));
16+
}

0 commit comments

Comments
 (0)