Title:
Write a function as an input string, the string inversion of vowels.
Example 1:
Input: "hello"
Output: "holle"
Example 2:
Input: "leetcode"
Output: "leotcede"
Description:
vowel does not contain the letter "y".
public class LeetCode345 {
public String reverseVowels(String s) {
if(s == null)
return null;
int l = 0;
int r = s.length()-1;
char[] str = s.toCharArray();
while(l<r){
if(isVowel(s.charAt(l)) && isVowel(s.charAt(r))){
char temp = str[l];
str[l] = str[r];
str[r] = temp;
l++;
r--;
}
if(!isVowel(str[l])){
l++;
}
if(!isVowel(str[r])){
r--;
}
}
return new String(str);
}
boolean isVowel(char c){
return c=='a' || c == 'e'|| c== 'i' || c== 'o' || c== 'u' ||
c=='A' || c == 'E'|| c== 'I' || c== 'O' || c== 'U' ;
}
}