We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fe20ed6 commit 88f1451Copy full SHA for 88f1451
Leet_Code/Random Problem/917-ReverseOnlyLetters.cpp
@@ -0,0 +1,19 @@
1
+class Solution {
2
+public:
3
+ string reverseOnlyLetters(string s) {
4
+ std::vector<char> v;
5
+ for(int p = 0; p < s.size(); p++){
6
+ if('a' <= s[p] && s[p] <= 'z'){v.push_back(s[p]);}
7
+ else if('A' <= s[p] && s[p] <= 'Z'){v.push_back(s[p]);}
8
+ }
9
+
10
+ std::reverse(v.begin(), v.end());
11
+ int idx(0);
12
13
+ if('a' <= s[p] && s[p] <= 'z'){s[p] = v[idx++];}
14
+ else if('A' <= s[p] && s[p] <= 'Z'){s[p] = v[idx++];}
15
16
17
+ return s;
18
19
+};
0 commit comments