My 12ms c++ simple solution


  • 3
    J
    class Solution {
    public:
        string reverseVowels(string s) {
            if (s.length() < 2) return s;
        string vowels="aeiouAEIOU";
            int i = 0, j = s.length()-1;
    
            while (i < j)
            {
                while (vowels.find(s[i])==string::npos && i<j) i++;
                while (vowels.find(s[j])==string::npos && i<j) j--;
                swap(s[i++],s[j--]);
            }
            return s;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.