题目要求:
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Given s = "hello", return "holle".
Example 2:
Given s = "leetcode", return "leotcede".
Subscribe to see which companies asked this question
public static String reverseVowels(String s) {
char[] st=s.toCharArray();
String vowels = "aeiouAEIOU";
int i=0;
int j=st.length-1;
while(i<j)
{
while(i<j && !vowels.contains(st[i]+""))
{i++;}
while(i<j && !vowels.contains(st[j]+""))
{j--;}
char temp=st[i];st[i]=st[j];st[j]=temp;
i++;j--;
}
return new String(st);
}