Reverse Only Letters - Solution

 ðŸ‘€✌Also Download our app CodeBox  from Play Store for offline use ðŸ‘€✌

SOLUTION

string reverseOnlyLetters(string s){
int i = 0, j = s.size()-1;
for (int i = 0; i < j; )
{
bool a = isalpha(s[i]);
bool b = isalpha(s[j]);
if(a && b){
swap(s[i],s[j]);
i++;
j--;
}else if(!a){
i++;
}else if(!b){
j--;
}
}
return s;
}

Comments