My C# solution


  • 0
    E
    public class Solution {
        public string ReverseVowels(string s) {
            string vowels = "aeiouAEIOU";
            var charArray = s.ToCharArray();
            int i = 0;
            int j = charArray.Length - 1;
            while (i < j)
            {
                if (!vowels.Contains(charArray[i]))
                    i++;
                if (!vowels.Contains(charArray[j]))
                    j--;
    
                if (vowels.Contains(charArray[i]) && vowels.Contains(charArray[j]))
                {
                    char temp = charArray[i];
                    charArray[i] = charArray[j];
                    charArray[j] = temp;
    
                    i++;
                    j--;
                }
            }
    
            return new string(charArray);
        }
    }

Log in to reply
 

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