T1:leetcode917 仅仅反转字母
class Solution {
public:
bool isStr(char c) {
if (c >= 'a' && c <= 'z') return true;
if (c >= 'A' && c <= 'Z') return true;
return false;
}
string reverseOnlyLetters(string s) {
int left = 0, right = s.size() - 1;
while (left <= right) {
if (isStr(s[left]) && isStr(s[right])) {
swap(s[left], s[right]);
left++;
right--;
continue;
}
if (!isStr(s[left])) left++;
if (!isStr(s[right])) right--;
}
return s;
}
};
/*
1.定义一个isStr函数判断是否为字母
2.对于单字符用char
*/