C++ solution in 32ms ez 2 understand


  • 0
    Y
        class Solution {
    public:
        string reverseVowels(string s) {
            int len=s.length();
            int begin=0;
            int end=len-1;
            while(begin<end){
                while(begin<end&&(!isvowel(s[begin]))){begin++;}
                while(begin<end&&(!isvowel(s[end]))){end--;}
                char temp;
                temp=s[begin];
                s[begin]=s[end];
                s[end]=temp;
                begin++;
                end--;
                
            }
            return s;
        }
        
        bool isvowel(char c){
            string v="aeiouAEIOU";
            for(int i=0;i<=v.length()-1;i++)
            {
                if(c==v[i]) return true;
            }
            return false;
        }
        
    };

Log in to reply
 

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