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".
Note:
The vowels does not include the letter "y".
String vowels = "aeiouAEIOU";
char[] sch = s.toCharArray();
start++;
end--;
class Solution {
public String reverseVowels(String s) {
if (s == null || s.length() == 0) {
return s;
}
String vowels = "aeiouAEIOU";
char[] sch = s.toCharArray();
int start = 0;
int end = s.length() - 1;
while (start < end) {
while (start < end && vowels.indexOf(sch[start]) == -1) {
start++;
}
while (start < end && vowels.indexOf(sch[end]) == -1) {
end--;
}
if (start < end) {
char temp = sch[start];
sch[start] = sch[end];
sch[end] = temp;
start++;
end--;
}
}
return String.valueOf(sch);
}
}