力扣第917题 仅仅反转字母
class Solution {
public:
bool isLetter(const char& c)
{
return 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z';
}
string reverseOnlyLetters(string S)
{
int left = 0, right = S.size() - 1;
char temp;
while (left < right)
{
while (right > left && !isLetter(S[left])) left++;
while (right > left && !isLetter(S[right])) right--;
if (left >= right)
{
break;
}
temp = S[left];
S[left] = S[right];
S[right] = temp;
left++;
right--;
}
return S;
}
};