Skip to content

Commit d19f899

Browse files
committed
src/bin/reverse-string.rs
1 parent 62df1a6 commit d19f899

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/bin/reverse-string.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
fn main() {}
2+
3+
struct Solution;
4+
5+
impl Solution {
6+
pub fn reverse_string(s: &mut Vec<char>) {
7+
if s.is_empty() {
8+
return;
9+
}
10+
let (mut s1, mut s2) = (0, s.len() - 1);
11+
12+
while s1 < s2 {
13+
s.swap(s1, s2);
14+
s1 += 1;
15+
s2 -= 1;
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)