Skip to content

Commit e1d1774

Browse files
authored
Two pointers and recursion
1 parent 82074ec commit e1d1774

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
void reverse_str(vector<char>& s, int left, int right)
4+
{
5+
if(left<right)
6+
{
7+
char a = s[left];
8+
s[left++] = s[right];
9+
s[right--] = a;
10+
reverse_str(s, left, right);
11+
12+
}
13+
else return;
14+
}
15+
16+
void reverseString(vector<char>& s)
17+
{
18+
int left = 0,right = s.size()-1;
19+
reverse_str(s, left, right);
20+
}
21+
};

0 commit comments

Comments
 (0)