Difficulty: Easy
leetcode url:https://leetcode.com/problems/reverse-vowels-of-a-string/
public String reverseVowels(String s) {
if(s.equals("")) return s;
char[] sc=s.toCharArray();
int i=0;
int j=sc.length-1;
while(i<j){
while(i<sc.length && i<j && !isVowel(sc[i])) i++;
while(j>0 && i<j && !isVowel(sc[j])) j--;
swap(sc,i,j);
i++;
j--;
}
return String.valueOf(sc);
}
public void swap(char[] sc,int i,int j){
char t;
t=sc[i];
sc[i]=sc[j];
sc[j]=t;
}
public boolean isVowel(char c){
if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U'){
return true;
}else
return false;
}