Skip to content

Commit a8c8fc5

Browse files
committed
Solution as on 01-04-2022 05:32 pm
1 parent 273bc94 commit a8c8fc5

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

0344. Reverse String.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,50 @@ class Solution
77
{
88
reverse(s.begin(), s.end());
99
}
10+
};
11+
12+
class Solution
13+
{
14+
public:
15+
void reverseString(vector<char> &s)
16+
{
17+
stack<char> st;
18+
19+
for (auto i : s)
20+
st.push(i);
21+
s.clear();
22+
while (!st.empty())
23+
{
24+
s.push_back(st.top());
25+
st.pop();
26+
}
27+
}
28+
};
29+
30+
class Solution
31+
{
32+
public:
33+
void solve(vector<char> &s, int i, int j)
34+
{
35+
if (i > j)
36+
return;
37+
swap(s[i], s[j]);
38+
solve(s, ++i, --j);
39+
}
40+
41+
void reverseString(vector<char> &s)
42+
{
43+
solve(s, 0, s.size() - 1);
44+
}
45+
};
46+
47+
class Solution
48+
{
49+
public:
50+
void reverseString(vector<char> &s)
51+
{
52+
int i = 0, j = s.size() - 1;
53+
while (i < j)
54+
swap(s[i++], s[j--]);
55+
}
1056
};

0 commit comments

Comments
 (0)