My C++ 12ms solution


  • 0
    C
    class Solution {
    public:
    	string reverseVowels(string s) {
    		int i = 0, j = s.size() - 1;
    		bool Isvowel[300];
    		memset(Isvowel, 0, 300);
    		Isvowel['A'] = true;
    		Isvowel['E'] = true;
    		Isvowel['I'] = true;
    		Isvowel['O'] = true;
    		Isvowel['U'] = true;
    		Isvowel['a'] = true;
    		Isvowel['e'] = true;
    		Isvowel['i'] = true;
    		Isvowel['o'] = true;
    		Isvowel['u'] = true;
    		while (i < j)
    		{
    			while (!Isvowel[s[i]] && i < j) i++;
    			while (!Isvowel[s[j]] && i < j) j--;
    			if (i < 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.