C++ 12ms one path


  • 2
    P
    bool IsVowel(char c)
    {
    	return (c == 'a') || (c == 'e') || (c == 'o') || (c == 'i') || (c == 'u') ||
    		   (c == 'A') || (c == 'E') || (c == 'O') || (c == 'I') || (c == 'U') ;
    }
    
    string reverseVowels(string s) 
    {
    	int slen = s.length();
    	for (int l = 0, r = slen - 1; l < r; ++l)
    	{
    		if (IsVowel(s[l]))
    		{
    			while ((l < r) && !IsVowel(s[r]) )
    				--r;
    
    			swap(s[l], s[r--]);
    		}
    	}
    	return s;
    }

Log in to reply
 

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