数组//反转字符串中的元音字母
编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
示例 1:
输入: "hello" 输出: "holle"
示例 2:
输入: "leetcode" 输出: "leotcede"
说明:
元音字母不包含字母"y"。
class Solution {
public String reverseVowels(String s) {
if(s == ""||s == null) return s;
int i = 0, j = s.length()-1;
char []str = s.toCharArray();
while(i < j){
while(i < j&&!judgeVowel(str[i]))
i++;
while(i < j&&!judgeVowel(str[j]))
j--;
if(i < j){
char temp = str[j];
str[j] = str[i];
str[i] = temp;
i++;
j--;
}
}
return new String(str);
}
public boolean judgeVowel(char c){
return c == 'a' | c == 'e' | c == 'i' | c == 'o' | c == 'u' |
c == 'A' | c == 'E' | c == 'I' | c == 'O' | c == 'U';
}
}