public class Test {
public static void main(String[] args) {
}
}
class Solution {
public String reverseOnlyLetters(String s) {
char[] chars = s.toCharArray();
int left = 0;
int right = chars.length - 1;
while (left < right) {
while (left < right && !Character.isLetter(chars[left])) {
left++;
}
while (left < right && !Character.isLetter(chars[right])) {
right--;
}
char c = chars[left];
chars[left] = chars[right];
chars[right] = c;
left++;
right--;
}
return String.valueOf(chars);
}
}