Skip to content

Commit 4e8a0f5

Browse files
committed
feat: add rust solution to lc problem: No.0344
No.0344.Reverse String
1 parent e6a1284 commit 4e8a0f5

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

solution/0300-0399/0344.Reverse String/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ var reverseString = function (s) {
9696
};
9797
```
9898

99+
### **Rust**
100+
101+
```rust
102+
impl Solution {
103+
pub fn reverse_string(s: &mut Vec<char>) {
104+
let n = s.len();
105+
let mut l = 0;
106+
let mut r = n - 1;
107+
while l < r {
108+
s.swap(l, r);
109+
l += 1;
110+
r -= 1;
111+
}
112+
}
113+
}
114+
```
115+
99116
### **...**
100117

101118
```

solution/0300-0399/0344.Reverse String/README_EN.md

+17
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ var reverseString = function (s) {
9090
};
9191
```
9292

93+
### **Rust**
94+
95+
```rust
96+
impl Solution {
97+
pub fn reverse_string(s: &mut Vec<char>) {
98+
let n = s.len();
99+
let mut l = 0;
100+
let mut r = n - 1;
101+
while l < r {
102+
s.swap(l, r);
103+
l += 1;
104+
r -= 1;
105+
}
106+
}
107+
}
108+
```
109+
93110
### **...**
94111

95112
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
impl Solution {
2+
pub fn reverse_string(s: &mut Vec<char>) {
3+
let n = s.len();
4+
let mut l = 0;
5+
let mut r = n - 1;
6+
while l < r {
7+
s.swap(l, r);
8+
l += 1;
9+
r -= 1;
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)