add: 220223-CN [cpp]
This commit is contained in:
parent
ecb3d135df
commit
6e2b99ed98
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include <string>
|
||||||
|
#include <cctype>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
static std::string reverseOnlyLetters(std::string s) {
|
||||||
|
int L = 0, R = s.length() - 1;
|
||||||
|
for (; L < R && !std::isalpha(s[L]); ++L);
|
||||||
|
for (; R && !std::isalpha(s[R]); --R);
|
||||||
|
for (; L < R; ++L, --R) {
|
||||||
|
for (; L < R && !std::isalpha(s[L]); ++L);
|
||||||
|
for (; R && !std::isalpha(s[R]); --R);
|
||||||
|
if (L >= R)
|
||||||
|
break;
|
||||||
|
std::swap(s[L], s[R]);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::cout << Solution::reverseOnlyLetters("-");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -3,4 +3,4 @@ PROJECT(2202)
|
||||||
|
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2202 220222.cpp)
|
ADD_EXECUTABLE(2202 220223-CN.cpp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue