Back to course home
0% completed
Vote For New Content
Dont need to convert string to array, reduce the space complexity to O(1)
Dang Khoa Tran
Jul 31, 2024
class Solution { public: bool isVowels(char c) { c = tolower(c); return c=='a' || c=='e' || c=='i' || c=='o' || c=='u'; } string reverseVowels(string s) { int i=0, j=s.length()-1; while (i<=j) { while(i<=j && !isVowels(s[i])) i++; while(i<=j && !isVowels(s[j]))j--; if (i<=j) { swap(s[i++], s[j--]); } } return s; } };
1
0
Comments
Comments