File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff 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};
You can’t perform that action at this time.
0 commit comments