diff --git a/reverseVowels_swaroop-phatak.cpp b/reverseVowels_swaroop-phatak.cpp new file mode 100644 index 0000000..adc3ca2 --- /dev/null +++ b/reverseVowels_swaroop-phatak.cpp @@ -0,0 +1,13 @@ +class Solution { +public: + string reverseVowels(string s) { + int i = 0, j = s.size() - 1; + string v = "aeiouAEIOU"; + while (i < j) { + while (i < j && v.find(s[i]) == string::npos) i++; + while (i < j && v.find(s[j]) == string::npos) j--; + swap(s[i++], s[j--]); + } + return s; + } +};