Clean C# code


  • 0
    public class Solution {
        public string ReverseVowels(string s) {
            if (s == null || s.Length == 0) return s;
            var chars = s.ToCharArray();
            int start = 0;
            int end = chars.Length - 1;
            
            while(start < end) {
                if (!IsVowel(chars[start])) start++;
                else (!IsVowel(chars[end])) end--;
                else {
                    var temp = chars[start];
                    chars[start] = chars[end];
                    chars[end] = temp;
                    start++;
                    end--;
                }
            }
            
            return new string(chars);
        }
        
        public bool IsVowel(char c) {
            return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'
                || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
        }
    }
    

Log in to reply
 

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