We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4275f31 commit b66f4e1Copy full SHA for b66f4e1
reverse-only-letters.cpp
@@ -0,0 +1,33 @@
1
+class Solution {
2
+public:
3
+
4
+ void swap(char &x, char &y){
5
+ auto t = x;
6
+ x = y;
7
+ y = t;
8
+ }
9
10
+ string reverseOnlyLetters(string S) {
11
12
+ if(S.size() == 0) return "";
13
14
+ int i = 0, j = S.size() - 1;
15
16
17
+ while(i <= j){
18
19
+ if(isalpha(S[i]) and isalpha(S[j]))
20
+ swap(S[i], S[j]);
21
22
+ else if(!isalpha(S[i])){
23
+ i++; continue;
24
25
+ else if(!isalpha(S[j])){
26
+ j--; continue;
27
28
29
+ i++; j--;
30
31
+ return S;
32
33
+};
0 commit comments