编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
示例 1:
输入: "hello"
输出: "holle"
示例 2:
输入: "leetcode"
输出: "leotcede"
while:
public static string ReverseVowels(string s)
{
var ss = s.ToCharArray();
int a = 0, b = s.Length - 1;
while (a<b)
{
while ("aeiouAEIOU".IndexOf(ss[a]) == -1 && a <= b - 1) a++;
while ("aeiouAEIOU".IndexOf(ss[b]) == -1 && b >= a + 1) b--;
if (a == b) return new string(ss);
var h = ss[a];
ss[a++] = ss[b];
ss[b--] = h;
}
return new string(ss);
}