-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec7_revStr.cpp
47 lines (40 loc) Β· 963 Bytes
/
lec7_revStr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// https://www.geeksforgeeks.org/problems/java-reverse-a-string0416/1?utm_source=geeksforgeeks&utm_medium=ml_article_practice_tab&utm_campaign=article_practice_tab
//seg fault
//{ Driver Code Starts
// Initial Template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function Template for C++
class Solution {
void rev(string &str , int start , int end)
{
if(start>=end)
{
return ;
}
char c = str[start] ;
str[start] = str[end];
str[end] = c;
rev(str , start + 1 , end -1);
}
public:
string revStr(string s) {
// code here
rev(s , 0 , s.size() -1);
return s;
}
};
//{ Driver Code Starts.
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
Solution ob;
cout << ob.revStr(s) << endl;
}
return 0;
}
// } Driver Code Ends